Server Side Filtering - Remove a specific query from the global filter

Server Side Filtering - Remove a specific query from the global filter

RobinSRobinS Posts: 11Questions: 4Answers: 1

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

  • RobinSRobinS Posts: 11Questions: 4Answers: 1
    Answer ✓

    Well, just as soon as posting, I figured it out. You can, indeed send the search to a specific column:

              dataTable
                .column(2)
                .search(query)
                .draw();
    

    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!!)

  • allanallan Posts: 63,892Questions: 1Answers: 10,530 Site admin

    Thanks for posting back, and your kind words. Great to hear you've got it working now.

    Allan

This discussion has been closed.