How can I tell if the user has performed a search?
How can I tell if the user has performed a search?
Hello Alan,
I would like to know if there's a way to check if the user has searched for something, as I have to clear the text in specific columns if the table is being filtered.
I would then use fnDrawCallback to clear the text, as hiding the columns would make the table resize and that would be weird.
Also, is fnDrawCallback the best approach to do so?
Thanks in advance
I would like to know if there's a way to check if the user has searched for something, as I have to clear the text in specific columns if the table is being filtered.
I would then use fnDrawCallback to clear the text, as hiding the columns would make the table resize and that would be weird.
Also, is fnDrawCallback the best approach to do so?
Thanks in advance
This discussion has been closed.
Replies
Is it the global filter (the one that DataTables adds automatically) that you are using (rather than a column specific filter)? If so - then yes I'd say fnDrawCallback is the way to go. DataTables provides a flag to indicate if the table has been filtered on a draw. You can do something like:
[code]
"fnDrawCallback": function ( oSettings ) {
if ( oSettings.bFiltered ) {
alert( 'Table has been filtered' );
} else {
alert( 'No filter on this draw' );
}
}
[/code]
There are other approaches as well - you could scan the internal settings object for the filtering string if you wanted (oSettings.oPreviousSearch.sSearch).
Regards,
Allan
I tried the code you posted - thanks for that btw - and oSettings.bFiltered was always returning true.
I'm now checking if oSettings.oPreviousSearch.sSearch is equal to an empty string and that seems to work fine.. I don't know if that's a bug in dataTables or in my script, but you may want to have a look.
Cheers,
Hugo
Regards,
Allan