Custom search not re-applied on draw()
Custom search not re-applied on draw()
I have created a custom search filter as per described here: http://datatables.net/development/filtering
to allow searching on the currently selected option label of a drop-down:
jQuery.fn.dataTableExt.ofnSearch['dom-select-label'] = function ( sData ) {
return sData.replace( /.?option.?>(.?)<./, '$1' ).split( /\s+|,\s+/)
}
With this line in the columDefs to apply it to col 3:
{ "type": 'dom-select-label', "targets": [ 3 ] },
This is working nicely following initial page creation. When I change the selection of the drop
down, I call .draw() on the table following my ajax call to inform the server - but the search filter
function is never called.
I was expecting this to happen as a result of the .draw() call.
Any suggestions?
Answers
Ok - I can answer myself: If I use .data() on the cell which contains my select, I can see it stores the id of the selected option value.
This needs to be explicitly updated using data( new option value ) for DT to register the change. Once this is done, the next call to .draw() does result in a single call to the custom filter.
Seems like DT has some onchange detection & only calls the the filter when the internal data changes.