Can I retrieve column/search specific data from a jQuery DataTable? -


i working on page web app displays member data in jquery datatable. building custom plugin datatable allows wide range of filtering per table column.

my current task able retrieve filtered data datatable, although not updating data on table. know possible retrieve filtered data doing:

var data = $table.datatable().$('tr', { filter: 'applied' }); 

this gets data text in search box , filters applied columns. aware call gets jquery selectors of cells. that's need. need more...

my questions are:

  1. can data applying what's in search box, without other current filters applied columns? tried:

    var data = $table.datatable().$('tr', { search: 'applied' });

but returns same { filter : 'applied' }.

  1. can target specific columns getting data, such as:

    var data = $table.datatable().$('tr', { filter: 'applied', columns: [1, 2, 5] });

  2. can target specific columns , what's in search box?

my plugin needs able keep track of data various combinations of column/search filters applied.

for datatables 1.9

there fnfilter() api method applies filtering table not want.

alternatively may want use fngetdata() data whole table , filter yourself.

for datatables 1.10

there search() api method applies filtering table when used draw() not want.

also there filter() api method. not you're looking close, need perform searching yourself.

you can retrieve content of search box follows:

var searchval = $('.datatables_filter input', $table).val(); 

then need searching yourself, shown below simplistic approach may not match how datatables perform search internally.

to search first , second column only, specify [0,1] columns() method. if no parameters specified, columns searched instead.

var filtereddata = $table.datatable()    .columns([0, 1])    .data()    .eq( 0 )    .filter( function ( value, index ) {        returrn (value.search(new regexp(searchval, "i")) !== -1)           ? true : false;    } ); 

according manual, variable filtereddata contain new api instance values result set passed test in callback.

to retrieve data or selected columns, use columns().data().


Comments