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

Convert from filter string to filter object

3 Answers 986 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 17 Sep 2014, 08:47 PM
Hello,

Is there is a means of converting a filter/sort/group query string (i.e. filter: "(Auditor~startswith~'John'~and~Company~contains~'Transport')") to a filter object that can be added via the dataSource.filter() method? I know of the parameterMap method that converts from object to string, but I'm interested in converting from string to object.

Any help would be greatly appreciated.

Thanks,

Garrett.

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 19 Sep 2014, 02:09 PM
Hello Garrett,

Filtering on nested complex object is not supported by the DataSource. You need to specify field which is of base type (string/number/date) and the corresponding value/operator that can be applied to it.

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-filter

Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Garrett
Top achievements
Rank 1
answered on 19 Sep 2014, 04:44 PM
Well, I'm saving the current grid configuration by adding it to the model during the Save event. I use this to do so:

function saveSearch(e) {
    // Get datasource of the filter grid, so we can save the search applied to it.
    var f = $("#filter-grid").data("kendoGrid").dataSource;
 
    // Set the filtering/sorting applied to the filter grid in the model being saved.
    e.model.Request = e.sender.dataSource.transport.parameterMap({
        filter: f.filter(),
        group: f.group(),
        page: f.page(),
        pageSize: f.pageSize(),
        sort: f.sort()
    });
};

Which returns this:

Object {
     sort: "InvoiceNumber-asc",
     page: 1,
     pageSize: 100,
     group: "",
     filter: "Auditor~startswith~'John'~and~Company~contains~'Transport'"
 }

I save the above object in a database. If I return multiple saved configurations to the page with the intention of applying them to a grid, the above object is returned. I can add a filter to the grid by calling the dataSource.filter() method with the filter object as a parameter, but the filter is returned in a string representation. There is a GridCommand.Parse() method that exists in your Kendo.Mvc.dll that does exactly what I'm looking for (although its only documented in the Telerik Extensions stuff), but I want to perform this on the page without calling a controller action. So, is there a similar method included in your jQuery framework, or will I need to implement my own method of parsing that string into a filter object again?
0
Garrett
Top achievements
Rank 1
answered on 20 Sep 2014, 04:48 PM
Nevermind, I implemented a method here. It does the trick for parsing filter query strings and sort query strings.
Tags
Data Source
Asked by
Garrett
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Garrett
Top achievements
Rank 1
Share this question
or