Language re-init ?

Language re-init ?

ChristilutChristilut Posts: 9Questions: 3Answers: 0

Hi,

This is what my DT looks like:

        $('#product-table-residual').DataTable({
            stateSave: true,
            dom: 'C<"clear">rtipf<"top"il<"clear">>t',
            colVis: {
                restore: window.locale["RestoreColumns"],
                exclude: [0],
                buttonText: window.locale["ChooseColumns"],
                overlayFade: 0,
            },
            serverSide: true,
            sAjaxSource: window.urlproductlist_residual, // old naming to force legacy
            columnDefs: [
                {
                    class: 'details-control',
                    orderable: false,
                    data: null,
                    defaultContent: '',
                    targets: 0,
                },
            ],
            language: {
                url: window.dtLanguageFile
            },
            order: [[1, 'asc']],
            initComplete: function () {
                colvis = $('.ColVis');
                colvis.appendTo($('.sorting_disabled.details-control:first'));
            }
        }).page(0),

The problem is that after I added the language parameter, the initComplete and columnDefs no longer work. I suspect that they do work but the language parameter causes a DT re-init, without calling initComplete and columnDefs.

How would I go about fixing this? I tried to hook into the init event but it has the same problem as initComplete.

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    The problem is that after I added the language parameter, the initComplete and columnDefs no longer work

    Can you please link to a test case showing this so I can debug it.

    Allan

  • ChristilutChristilut Posts: 9Questions: 3Answers: 0

    I couldn't manage to reproduce it in the live.datatables site (ajax requests and stuff) but after fiddling around some more I've narrowed it down.

    url: window.dtLanguageFile
    

    contains the server URL for the .json file. If I change that line to

    url: '//cdn.datatables.net/plug-ins/a5734b29083/i18n/English.json'
    

    it works fine. The file itself is the same.
    So not sure exactly what the cause is, but I'm guessing it is a server configuration issue. I'll stick with the datatables CDN for now.
    Thanks!

  • ChristilutChristilut Posts: 9Questions: 3Answers: 0

    Actually I then realized whats going on.

    If the language URL is invalid, it apparently causes the behavior I've seen.

    Here's a jsbin: http://live.datatables.net/peyivizi/1/edit

    Notice theres no alert with the invalid url. Remove the language paramter and the alert happens.

    Hope this helps!

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Ah interesting. Thanks for letting me know about that.

    I've just committed a fix so that if the language file fails to load, it will just continue using the defaults (or the client-side specified options if there are any). I've made a couple of related changes which saves about 20 bytes from the library size, so I'm happy :-).

    The nightly is rebuilding at the moment and will shortly be available with this fix on the downloads page.

    Allan

This discussion has been closed.