This is a migrated thread and some comments may be shown as answers.

Filtering blank strings using <kendo-string-filter-menu>

3 Answers 778 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
rk
Top achievements
Rank 1
rk asked on 04 Mar 2019, 07:28 PM

I have a grid column that has several fields with blank strings ("    "). I want to filter them using one of the operators available from list for <kendo-string-filter-menu>. 

The 'Is empty' operator filters strings that have length 0 ("") . It fails to filter ("   ") blank spaces as part of criteria. None of the operators available solved my problem. 

This is kind of critical to a requirement that working on. Can you please help. 

Thanks.
Ramakrishna Reddy Bairi,
Wells Fargo

3 Answers, 1 is accepted

Sort by
1
Dimiter Topalov
Telerik team
answered on 05 Mar 2019, 09:19 AM
Hello Ramakrishna,

You can find the same answer in the private support thread with the same subject, but I will also paste it here so others can benefit too:

Indeed, this is the expected behavior, as an empty string is one with length 0, and not one with varying length, but composed of white spaces.

A sample approach for achieving the desired behavior would be to check the incoming filter descriptors in the filterChange/dataStateChange event handler of the Grid, and if there is a filter by the respective string field, and the operator is "isempty", replace the operator with a custom function that will apply the custom filtering criteria, e.g.:

public dataStateChange(state: any): void {
      console.log(state)
      const prNameFilter = state.filter.filters.find(f => f.field === 'ProductName');
      console.log(prNameFilter)
      if(prNameFilter) {
        if(prNameFilter.operator === 'isempty') {
          prNameFilter.operator = (value) => value.trim() === '';
        }
      }
        this.state = state;
        this.gridData = process(sampleProducts, this.state);
    }

https://stackblitz.com/edit/angular-ffigrv?file=app/app.component.ts

On a side note, for future reference - please open one support thread per issue/question only. This will facilitate a tidier support history of your account and better support service. For the currently discussed issue you can choose which of the two threads to continue the communication in if necessary. Thank you in advance.

Regards,
Dimiter Topalov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
1
rk
Top achievements
Rank 1
answered on 05 Mar 2019, 09:20 PM

Hi 

Thank you for the solution. 

Is there a way to push a custom operator into the list of operators available. Like "isblank' operator for this purpose.

0
Dimiter Topalov
Telerik team
answered on 06 Mar 2019, 07:06 AM
Hi Ramakrishna,

The only way to introduce custom operators and the respective underlying custom filtering logic, would be to create a custom reusable filter cell (or filter menu) component, using the respective FilterCell and FilterMenu templates.

This will give you full control over the content and functionality of the Grid filter, and you will be able to use for example a DropDownList with all desired options for the filtering options, and then change the filter descriptor that is propagated to the Grid with the respective operator in the DropDownList's valueChange event handler.

Examples of creating custom filtering components are available in the following sections of our documentation:

https://www.telerik.com/kendo-angular-ui/components/grid/filtering/reusable-filter/#toc-row-filtering

https://www.telerik.com/kendo-angular-ui/components/grid/filtering/reusable-filter/#toc-menu-filtering

Alternatively, you can just rename the Is Empty operator to Is Blank in the UI via the CustomMessages component, and keep the previously discussed approach for the customized filtering operation, e.g.:

https://stackblitz.com/edit/angular-ffigrv-atp2tj?file=app/app.component.ts

Regards,
Dimiter Topalov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
rk
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
rk
Top achievements
Rank 1
Share this question
or