简体   繁体   中英

Jquery datatable filter by text

I am using the below code to filter the record from jquery data table.My data table format like this

 var aDataSet = [['1', 'GOld', 'G-110,G-112,G-123', 'G1-001,G1-005,G1-008'],
                ['2', 'GOld type 1', 'G1-001,G1-003,G-123', 'G-110,G-112,G-156']];


 $(document).ready(function () {
                oTable = $('#example').dataTable();
                oTable.fnFilter('G-110,G-112');
            });

Suppose i give the input value like 'G-110,G-112' to the above function means the out put like this

The above two records are displayed.

Suppose my input is G1-001,G1-003,G-156 means the second record only displayed.

I want to filter the most of the item present in the data table row.

you have to include check for the regexp in fnFilter function :

fnFilter function has these elements as parameter s:

  • {string}: String to filter the row on
  • {int|null}: Column to limit filtering to
  • {bool} [default=false]: Treat as regular expression or not
  • {bool} [default=true]: Perform smart filtering or not
  • {bool} [default=true]: Show the input global filter in it's input box(es)
  • {bool} [default=true]: Do case-insensitive matching (true) or not (false)

so your filter function should look like this:

oTable.fnFilter('G-110,G-112',null,true); 
//this will check your row based on regular expression also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM