Hiding records in datatable

Hiding records in datatable

chrisjai32chrisjai32 Posts: 10Questions: 4Answers: 1

What i want to do is hide the records/data from the datatable so by default it will show "no data available in table", But when the user uses the search function, it will display the matching records.

Thank you very much!

Answers

  • chrisjai32chrisjai32 Posts: 10Questions: 4Answers: 1

    I've been searching around and i put "deferLoading: 0" on my script and it does what i like to do which is not diplay my records when the page loads but after i delete my search the datatable doesnt return back to being empty. any solution ? thank you so much.

    my script:


    $(document).ready(function(){ var dataTable = $('#example').dataTable({ dom: 'T<"clear">lfrtip', "tableTools": { "sSwfPath": "../assets/swf/copy_csv_xls_pdf.swf", "sRowSelect": "multi", "aButtons": [ "select_all", "select_none", { "sExtends": "collection", "sButtonText": "Advance Tools", "aButtons": [ "csv", "xls", "pdf","print" ] } ] }, bProcessing: true, bServerSide: true, bRegex:true, "oLanguage" : {"sZeroRecords": "", "sEmptyTable": ""}, deferLoading: 0, sRowEmpty: true, sAjaxSource: "server_processing.php" }); });
  • chrisjai32chrisjai32 Posts: 10Questions: 4Answers: 1

    up

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    According to your initialization, you are using serverSide processing. Since you are using serverSide Processing you should be examining the passed search variables in the GET / POST request. If they are empty, then add a conditional to your ajax page to return an empty json set of [].

  • chrisjai32chrisjai32 Posts: 10Questions: 4Answers: 1

    thank you for answering, sorry but can you give me an example ?

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Did you write the ajax page "server_processing.php"?

    Since you are performing serverside, you should be crafting the SQL query string. Normally for serverside processing, it's up to the user to craft the SQL from the parameters in the request object (the ajax page request object). The "where" clause and the "limit" clause are based upon what's in the request object. Since you should be creating the sql clause, if the filter value are all empty, don't perform a query / database call at all. Instead just return '[]' as your ajax page response.

This discussion has been closed.