Custom Filter
Last updated
Last updated
index
/ /
You can also create your own Custom Filter with any html/css you want to use. Vue template (View) are not supported at this point, if you wish to contribute on that end then I certainly accept PR (Pull Request).
Limitations
as mentioned in the description, only html/css and/or JS libraries are supported.
this mainly mean that Vue templates (Views) are not supported (feel free to contribute).
SlickGrid uses table-cell
as CSS for it to display a consistent height for each rows (this keeps the same row height/line-height to always be the same).
all this to say that you might be in a situation were your filter shows in the back of the grid. The best approach to overcome this is to use a modal if you can or if the library support append to body container
. For example, you can see that multiple-select.js
support a container
and is needed for the filter to work as can be seen in the
You first need to create a class
using the . Make sure to create all necessary public properties and functions.
You can see a demo with a that is used in the
There are two methods to use your custom filters on the grid.
Simply set the columnDefinition.filter.model
to your new custom Filter class and instantiate it with new
(you can also use dependency injection in the constructor if you wish). Here is an example with a custom input filter:
myCustomFilter.ts
my-view-model.ts
main.ts
If you want to load the grid with certain default filter(s), you can use the following optional properties:
searchTerms
(array of values)
For example, setting a default value into an input
element, you can simply get the search term with columnDef.filter.searchTerms
and set the default value with filterElm.value = searchTerms;
If you want to pass a collection
to your filter (for example, a multiple-select needs a select list of options), you can then use it in your custom filter through columnDef.filter.collection
key/label
pair
By default a collection
uses the label/value
pair. You can loop through your collection
and use the label/value
properties. For example:
Custom Structure (key/label pair)
What if your collection
have totally different value/label pair? In this case, you can use the customStructure
to change the property name(s) to use. You can change the label and/or the value, they can be passed independently. For example:
LabelKey
By default a collection
uses the label/value
pair without translation or labelKey/value
pair with translation usage. So if you want to use translations, then you can loop through your collection
and use the labelKey/value
properties. For example:
What if you want to use customStructure
and translate the labels? Simply pass the flag enableTranslateLabel: true
For example:
Or register your filter with the registerTransient
method on the Vue container in the startup file (see the demo . It is recommended to use registerTransient
, though you could use whatever lifetime you want). This registration is usually in main.ts
or main.js
. Then in your view model pass your custom filter to columnDefinition.filter.model
property and we will use Vue's container to instantiate your filter. Here is that example:
By default, the library uses the when none is specified. However, you can override this value with any filter you like during the startup/configuration of your Vue application: