language setting in datatables

language setting in datatables

AkashvinoAkashvino Posts: 15Questions: 8Answers: 0

Hi All,

We have a dropdown menu with 4 options, each options provides a url(surl: fetch's data from the same table with different queries), while the page is first loaded we can see the message as "Loading...", when we choose the 2 or 3 or 4 option it dispaly "No data avaliable in table" and later after few mins the data is displayed, so need your help on this as our requirnment is to display "Loading..." when we choose other option and display "No records available" only when the table is actualy empty. Belos is our code

<script type="text/javascript">
$(document).ready(function(){
    $('#Slist').bind('change init', function(){
    ('#Server').toggle($("#Slist option").is(':selected'));
    var rvalue = this.value;
    var surl = '/Serv/' + rvalue;
    var table = $('#Server').DataTable(); 
    table.clear().destroy();
    var table = $("#Server").DataTable({
        language: { loadingRecords: "Loading..." },
        saveState: true,
        ajax: { url: surl, dataSrc: "", method: "GET", xhrFields: { withCredentials: true } },
        
        columns: [ { data: "ServerName", className: "text-sm-center h8 px-0" } ],
        deferRender: true,
        initComplete: function (settings, json) { language: { emptyTable: "No records available" } }
    });
    }).trigger('init');
});
</script>

From,
Vino

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    edited April 2020

    The default of "emptyTable" is "No data available in table". You changed that for an empty table when initialization is complete. When the table is about to be redrawn you would also need to change that message and of course again when the draw is completed.
    You could try and add this.

    preDrawCallback: function( settings ) {
        language: { emptyTable: "Loading..." } 
    }
    drawCallback: function( settings ) {
        language: { emptyTable: "No records available" } 
    }
    
This discussion has been closed.