Search code examples
jquerydatatablesloadercustom-url

jQuery DataTable custom language url works, but loader doesn't


Is it possible in jQuery dataTable to add loader when it has a custom language url? For example:

"language": 
  {          
    "processing": "<span style="width:100%;"><img src="http://www.snacklocal.com/images/ajaxload.gif"></span>",
     "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
  }

When I have both it doesn't work, but if i comment url line, loader works.


Solution

  • I founded this article and I sent message to DataTable forum, and they sad:

    This is something that is going to be added in for v2 of DataTables, which is in progress, but slowly.

    Until then you would need to load the Ajax language information using $.getJSON (or similar) and then merge it into your local object as needed, then using the result in the DataTable configuration

    UPDATE: I comment my source line and added text manually like this:

            "language": {
             // "sUrl": "../HTMLRepository/JsLocalization/DataTableLocalization_Serbian.json"
            "sEmptyTable": "Ni jedan podatak ne postoji za zadate kriterijume",
            "sInfo": "Prikaz _START_ do _END_ od ukupno _TOTAL_ redova po strani",
            "sInfoEmpty": "Prikaz 0 do 0 od ukupno 0 redova",
            "sInfoFiltered": "(filtrirano od ukupno _MAX_ redova)",
            "sInfoPostFix": "",
            "sInfoThousands": ",",
            "sLengthMenu": "Prikaz _MENU_ redova",
            "sLoadingRecords": "Molimo sačekajte, učitavanje u toku...",
            "sSearch": "Pretraži:",
            "sZeroRecords": "Podaci se ne podudaraju",
            "oPaginate": {
                "sFirst": "Prva",
                "sLast": "Poslednja",
                "sNext": "Sledeća",
                "sPrevious": "Predhodna"
            }          
        },
    

    And in $(document).ready function i have

    $('#patientsTable').on('processing.dt', function (e, settings, processing) {
        if (processing) {
            activateLoader();
            activateOverlay();
        }
        else {
             deactivateLoader();
             deactivateOverlay();
       }
    

    And finally it works :) Thanks a lot @Shiladitya