Search/filter table before load

Search/filter table before load

jonmrichjonmrich Posts: 12Questions: 6Answers: 0

I'm using the following to render my table and it works fine:

`$(document).ready(function() {
$("#occupations_datatable").DataTable({

"ajax": {
"url":"occupations.php",
"type":"GET"
} ,

"paging": true,
"sDom": '<"top">t<"bottom"><"clear">',
"pageLength": 50,
"order": [[ 1, "desc" ]],

"aoColumns": [
{ "bSortable": true, "width": "40%", "sClass": "lang_body_2", "sTitle": "", "visible":false },
{ "bSortable": true, "width": "40%", "sClass": "lang_body_2", "sTitle": "" },
{ "bSortable": true, "width": "20%", "sClass": "lang_body_2", "sTitle": "Database"},
{ "bSortable": true, "width": "20%","sClass": "lang_body_2","sTitle": "National Average" },
{ "bSortable": true, "width": "20%","sClass": "lang_body_2 index_num table_index","sTitle": "Index" },

],
});

});`

Here's my question...what can I add to this so that the table only renders rows with a certain string in column 0 (the one set to visible:false)? I've tried a bunch of things, but can't figure out how to search/filter before the table loads. I can figure out how to do it on, say, a button click, but I want to search/filter before the table is even rendered. Any help would be appreciated.

Thanks,
JMR

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Assuming your data source is a database, you will need the appropriate query in your "occupations.php" script.

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    Take a look at the server side configuration of my yadcf plugin and the usage of yadcf.exFilterColumn function (see code snippet on page buttom):
    http://yadcf-showcase.appspot.com/server_side_source.html

    Its not exactly what you where looking for (table first page does being loaded) but its something...

This discussion has been closed.