oLanguage in combination with sDom <"toolbar"> bug?

oLanguage in combination with sDom <"toolbar"> bug?

ArnoArno Posts: 3Questions: 0Answers: 0
edited February 2011 in Bug reports
Hi,

Compliments on Datatables!

When I try to use sDom to add a div class (like the example "DataTables Custom DOM additions") I noticed this doesn't work when I use it in combination with oLanguage. The "$("div.toolbar").html('Custom tool bar! Text/images etc.');" doesn't show.
When I comment out the oLanguage line, the Custom tool bar text is shown.

Is this a bug or am I doing something wrong?

Thanks,
Arno

Replies

  • MiYaGiNMiYaGiN Posts: 3Questions: 0Answers: 0
    Same problem here, i can see div toolbar on html resoult, but there is not html code inside it. If i take out Olanguage line it works...
  • MiYaGiNMiYaGiN Posts: 3Questions: 0Answers: 0
    It only happens whern you use sUrl calling an external language file, on jquery.dataTables.js file, it changes bInitHandedOff to true, and it doewsnt show the rest of the HTML text, but ifyou change it to false, it show correct header and then incorrect one....
  • ArnoArno Posts: 3Questions: 0Answers: 0
    Miyagin: thanks for the info.

    Allan: Is this a bug in datatables?
  • MiYaGiNMiYaGiN Posts: 3Questions: 0Answers: 0
    Arno, i have just use the olanguge code inside the $(document).ready(function(). and not the sUrl, I use datatables in joomla, i just take the language from user and then:

    ...
    <?php
    if ($language='es_ES') { ?>
    "oLanguage": {
    "sLengthMenu": "Mostrar _MENU_ registros por página",
    "sZeroRecords": "No hay resultados",
    "sInfo": "Mostrando _START_ a _END_ de un total de _TOTAL_ registros",
    "sInfoEmpty"....}
    <?php }

    ... and so with all my languages.
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    This is intentional and a side effect of the async loading of the language file. Remember that it's using Ajax to get it, so the line which does the insert of the toolbar, is executed before DataTables has set up the table (since it's still loading the language file, so can't do much more...).

    To solve this you can use fnInitComplete ( http://datatables.net/usage/callbacks#fnInitComplete ) which is fired once the table has fully initialised:

    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "oLanguage": {
    "sUrl": "whatever"
    },
    "fnInitComplete": function () {
    $("div.toolbar").html('Custom tool bar! Text/images etc.');
    },
    "sDom": '<"toolbar">frtip'
    } );
    } );
    [/code]
    Allan
  • ArnoArno Posts: 3Questions: 0Answers: 0
    Miyagin: thanks.. that is what I am using now!

    Allen: I use a button instead off the "Custom tool bar" text. In your example the button doesn't seem to function anymore (the click event isn't picked up). Probably a coding error somewhere in my code. I am using Miyagin's option since that is the easiest and I don't have the time to investigate and rewrite the code..


    Thanks for the help!
  • GuigozGuigoz Posts: 8Questions: 0Answers: 0
    In order to keep the sUrl system you can also use the PHP (or other language) include function in order to include the content of the oLanguage parameter.

    It looks like Miyagin's response but we don't have some IF/ELSE IF/... in the JS code :

    Example :

    [code]
    $('#table').dataTable({
    "sDom": 'blahblah',
    "oLanguage": <?php include 'pathToYourLanguageDirectory/'.$userLanguage.'.js'; ?>,
    });
    [/code]

    it will include the content of the EN.js or FR.js files into the oLanguage parameter.

    The language files can be found here : http://datatables.net/plug-ins/i18n
This discussion has been closed.