Apply grid filter from transport string?

1 Answer 319 Views
Data Source Filter Grid
Koen
Top achievements
Rank 1
Koen asked on 07 Sep 2021, 08:40 AM | edited on 08 Sep 2021, 09:25 AM

Hi!

Can I also apply a filter string representation read from a filter transport.parameterMap?

let grid = $('#myGrid').data("kendoGrid");

// This works, apply filter from object
grid.dataSource.filter({ field: "amount", operator: "eq", value: 7 });

// read the grid' filter as string
let filterstring = grid.dataSource.transport.parameterMap({ filter: grid.dataSource.filter() }).filter;
// value is now "amount~eq~7"

// Q: can something like this be done in some way?
grid.dataSource.filter("amount~eq~1234567"); // bad code

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 09 Sep 2021, 08:27 PM

Hello Koen,

To confirm, the Kendo UI DataSource's filter cannot be set using a string value.  But, the Kendo UI DataSource's filter can be configured using an object which has a field, operator, and value defined like what you presented in the snippet.  If you have a string in the format provided(filterString), you can split the string and populate the dataSource filter:

JavaScript

        //reference the grid
        let grid = $('#grid').data("kendoGrid");

        // read the grid' filter as string
        let filterstring = "UnitPrice~eq~18";

        //split the filterString
        var newFilter = filterstring.split("~");

        //set the filter of the Kendo UI Grid's DataSource
        grid.dataSource.filter({ field: newFilter[0], operator: newFilter[1], value: newFilter[2] });

Please let me know if you have any questions regarding the matter.

Regards,
Patrick
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Koen
Top achievements
Rank 1
commented on 14 Sep 2021, 01:22 PM

Since I only require to filter a single member, this works perfect for me.

Thanks!

Patrick | Technical Support Engineer, Senior
Telerik team
commented on 14 Sep 2021, 01:41 PM

Glad to hear this solution helped out!   
Tags
Data Source Filter Grid
Asked by
Koen
Top achievements
Rank 1
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
Share this question
or