Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter data on page load using jQuery DataTables plugin? [closed]

I am using the jQuery DataTables plugin in my application and am displaying a set of data with multiple years. When the page loads, I'd like the data to start filtered to the current year. Is it possible to have the plugin filter data when the page loads?

like image 352
Michael Avatar asked Dec 02 '22 23:12

Michael


1 Answers

As Datatables API says:

$(document).ready(function() {
    oTable = $('#example').dataTable();

    /* Filter immediately */
    oTable.fnFilter( 'test string' );
} );

If you need to Filter only a specific column, use (zero-based) columnIndex as second parameter:

    oTable.fnFilter( 'test string', columnIndex );
like image 139
Georg Engel Avatar answered Jan 17 '23 13:01

Georg Engel