question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set custom header filter operator for ajax filtering?

See original GitHub issue

Hi Tabulator Team,

First of all thanks for your awesome work. I started using Tabulator a month ago and I started loving Tabulator.

I’m trying to pass a custom header filter operator for each column in my ajaxFiltering, but the filter params always returns like value.

here is my scenario. i’ll be sending my filters in the server url as follows: https://localhost/api/test?search=name eq test&dob gt 12/12/2012&...

so in my columns definition,

      {
        title: 'Name',
        field: 'name',
        headerFilter: 'input',
        headerFilterLiveFilter: false,
        type: 'eq'
      },
      {
        title: 'DOB',
        field: 'dob',
        headerFilter: 'input',
        headerFilterLiveFilter: false,
        type: 'gt',
      },...

But my params.filters array in ajaxURLGenerator always returns type: "like" for all the fields. it would be nice if there is an option to make my params.filters array to return the type I mention in the column definition of each column like type: "eq", type: "gt", etc…

Am I missing something from docs?

I searched and could’nt find a way. Help would be much appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tentuscommented, Mar 22, 2019

To my knowledge there’s not a way to register in new kinds of filters (though admittedly my knowledge is very limited). From looking at your examples though, it kind of seems like you’re looking to just translate the types over to a format your api accepts, not adding any unusual new kinds of filters. If that’s the case, you can iterate over the params.filters in the ajaxURLGenerator function like you mentioned and swap out the types, like so:

          const operators = {
            '=': 'eq',
            '>': 'gt',
            '>=': 'gte',
            '<': 'lt',
            '<=': 'lte',
            '!=': 'neq',
          };

          (params.filters || []).forEach(function (filter) {
            filter.type = operators[filter.type] || filter.type;
          });
0reactions
olifolkerdcommented, Mar 25, 2019

Hey @fingers10 @tentus

Almost everything in Tabulator is customisable. everything is built as modules and pretty much anything where you pick from a list of built in options can be extended to add your own.

Custom Filter Function

You can either pass a callback into the headerFilterFunc which is covered in the Header Filter Documentation

Extend Filter Module

You can also expand Tabulator to add custom built in filters, checkout the Filter Module Docs for more information on how to do this,

You can then pass that string of the key into the headerFilterFunc to reference a specific filter.

Because this string is passed back in the ajax request if all you need it for is to pass back the string you can define the filter function as an empty callback and it will do what you need.

I hope that helps,

Cheers

Oli 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering Data - Tabulator
It is possible to filter the table data directly from the column headers, by setting the headerFilter option in the column definition object...
Read more >
Filtering and Searching - DevExtreme - DevExpress
A header filter's popup menu lists all column values by default. You can group them using the headerFilter.groupInterval property if they are numbers...
Read more >
issue in datatable filter using custom ajax call - Stack Overflow
I believe that using some DataTables script I usually use the following cdn which works very well at the beginning of the scope....
Read more >
Grid Filter Menu - Telerik UI for Blazor
To enable the filter menu, set the FilterMode property of the grid to Telerik.Blazor.GridFilterMode.FilterMenu . The grid will render a button in the...
Read more >
Advanced AJAX Product Filters - Plugins - WordPress.org
Advanced Settings (Plugin Settings): · Plugin settings can be found in admin area, WooCommerce -> Product Filters · “No Products” message – Text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found