Server Side Filtering - Remove a specific query from the global filter
Server Side Filtering - Remove a specific query from the global filter
Hi All! First time poster but I've been using datatables at various points in my career :-)
Anyway, I have a table that's using serverside ajax, and it has a filter on the date column for a from date and to date. I have this working using (this is Angular 2/typescript):
element.on('change', '.date-group input', function () {
if (document.getElementById('from') && document.getElementById('to')) {
const fDateStart = (<HTMLInputElement>document.getElementById('from')).value;
const fDateEnd = (<HTMLInputElement>document.getElementById('to')).value;
const mDateStart = fDateStart ? moment(fDateStart, 'DD-MMM-YY') : null
const mDateEnd = fDateEnd ? moment(fDateEnd, 'DD-MMM-YY') : null
if (mDateStart === null && mDateEnd === null) {
return
}
let query=`${fDateStart}&${fDateEnd}`
dataTable
.search(query)
.draw();
}
and then I do some ternary stuff on the ajax parameters
fromDate: data.search.value.split('&')[0] ? moment(data.search.value.split('&')[0], 'DD-MMM-YY').toISOString() : this.fromDate.toISOString(),
toDate: data.search.value.split('&')[1] ? moment(data.search.value.split('&')[1], 'DD-MMM-YY').toISOString() : this.toDate.toISOString(),
Anyways, this works but my only problem is that the query string, e.g. "17-May-17&24-May-17" displays in the filter, which is not great looking. Is there a way I can remove this after the search has posted? Like a certain hook I can use? Or force it to do the search on the dateTime column, even though they're custom inputs?
This question has an accepted answers - jump to answer
Answers
Well, just as soon as posting, I figured it out. You can, indeed send the search to a specific column:
I'll leave this post in case someone else has a similar question (or it can be deleted - either way!)
Thanks for this fantastic plugin (and keeping up with it all these years!!)
Thanks for posting back, and your kind words. Great to hear you've got it working now.
Allan