Zero record hidden after creating defaults

Zero record hidden after creating defaults

MisiuMisiu Posts: 68Questions: 4Answers: 2
edited November 2012 in Bug reports
After moving my oLanguage to defaults zero record row is missing.

When I add oLanguage to dataTable initialization it works fine, but when I move it into $.extend($.fn.dataTable.defaults,{}) this row is hidden.

Please take a look at this demo: http://jsfiddle.net/PGM4b/

When page is loaded zero records row is hidden, when You change number of rows per page it is visible again.

Demo uses dataTables 1.9.0, but I'm using 1.9.4 and the results are the same.

Replies

  • TiaxTiax Posts: 12Questions: 0Answers: 0
    Pass true as the first parameter to $.extend to make a deep copy (see http://api.jquery.com/jQuery.extend/)
  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    As so:
    [code]
    $.extend(true, $.fn.dataTable.defaults, {
    "oLanguage": {
    "sProcessing": "Proszę czekać...",
    "sLengthMenu": "Ilość rekordów na stronie: _MENU_",
    "sZeroRecords": "Brak rekordów",
    "sInfo": "Pozycje od _START_ do _END_ z _TOTAL_ łącznie",
    "sInfoEmpty": "Pozycji 0 z 0 dostępnych",
    "sInfoFiltered": "(filtrowanie spośród _MAX_ dostępnych rekordów)",
    "sInfoPostFix": "",
    "sSearch": "Szukaj:",
    "sUrl": "",
    "oPaginate": {
    "sFirst": "Pierwsza",
    "sPrevious": "Poprzednia",
    "sNext": "Następna",
    "sLast": "Ostatnia"
    }
    }
    });
    [/code]

    If I do so my table is displayed, but without localization.
    Could You please show me the correct usage?
  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    It is possible to extend defaults, but I would like to add default localization into my default.
    This particular part isn't working.
  • TiaxTiax Posts: 12Questions: 0Answers: 0
    working fine, you just didn't provide a translation for "sEmptyTable" in your oLanguage object ;)
  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    Thanks Tiax :)
    I didn't notice that there is another option in oLanguage that I must use.
    It's a bit weird that when I add translation into dataTable initialization I see sZeroRecords translation in my row (when I initialize dataTable on empty table), but when I want to use it in default setting, using extend, I must specify another option - sEmptyTable.
    I don't know if this is a true bug, but it's bit confusing.
  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    There still is something wrong.
    I'm trying do move all my settings to $.extend, because I'm using the same table 3 times on a page, the only difference are the columns.

    I'm trying to add "aLengthMenu" to my defaults.
    When I use deep copy aLengthMenu is broken, when I remove true from extend language is broken.

    Please take a look at: http://jsfiddle.net/PGM4b/5/
    As You can see length menu has some weird options, but when You remove true from $.extend it works, but then initial translation is missing-row saying no data in table.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    The problem here is that the default for aaLengthMenu is:

    [code]
    [ 10, 25, 50, 100 ]
    [/code]

    So when you extend it with your 2D array you actually get:

    [code]
    [
    [25, 50, 100, -1],
    [25, 50, 100, "Wszystkie"],
    50,
    100
    ]
    [/code]

    which confuses DataTables somewhat and we get the result that you see.

    Possibly DataTables should take this into account, but is it effectively an invalid value. Rather than extending the aLengthMenu option - just assign it directly:

    [code]
    $.fn.dataTable.defaults.aLengthMenu = [[25, 50, 100, -1], [25, 50, 100, "Wszystkie"]];
    [/code]

    http://jsfiddle.net/PGM4b/6/

    Allan
  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    Thanks for such a fast response Allan.

    I found sample aLengthMenu in reference: http://datatables.net/ref#aLengthMenu so I was trying to do it this way.

    Thank You for help!

    Every time I use DataTables I get more and more amazed! :)
This discussion has been closed.