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

Complex filtering problem

2 Answers 156 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 29 Nov 2013, 12:34 PM
I am creating a fairly simple datasource, with at least two filters but possibly more depending on what the user has set up.  When I have two filters it is fine.  I set the datasource filter up as follows:

{
logic: "and",
filters: [
    { field: date, operator: "gte", value: "01/11/2013" },
    { field: date, operator: "lte", value: "30/11/2013" },
]
}

This works correctly when I fetch the data.  However if I have a 3rd filter I get the error: "Unable to cast object of type 'Kendo.Mvc.CompositeFilterDescriptor' to type 'Kendo.Mvc.FilterDescriptor'."

I have tried a few structures for the filter:
{
logic: "and",
filters: [
    { field: date, operator: "gte", value: "01/11/2013" },
    { field: date, operator: "lte", value: "30/11/2013" },
    { field: userName, operator: "eq", value: "JBLOGGS" }
]
}

{
logic: "and",
filters: [ {
    logic: "and",
    filters: [
    { field: date, operator: "gte", value: "01/11/2013" },
    { field: date, operator: "lte", value: "30/11/2013" }] },
    { field: userName, operator: "eq", value: "JBLOGGS" } ]
    }
]
}

And other variations, but all of them give the same error.

Any help would be appreciated.
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 02 Dec 2013, 02:41 PM
Hello Karl,

The second filter object that you shared is not valid JSON:

{
logic: "and",
filters: [ {
    logic: "and",
    filters: [
    { field: date, operator: "gte", value: "01/11/2013" },
    { field: date, operator: "lte", value: "30/11/2013" }] },
    { field: userName, operator: "eq", value: "JBLOGGS" } ]
    }
]
}

Here is what I tried on my side and it is working fine.


$(function () {
    $('#people').data('kendoGrid').dataSource.filter([{
        logic: "and",
        filters: [
            { field: "BirthDate", operator: "lte", value: "11/01/2013" },
            { field: "BirthDate", operator: "lte", value: "11/30/2013" },
            {
                logic:"or",
                filters: [
                    { field: "BirthDate", operator: "eq", value: "06/26/1968" },
                    { field: "BirthDate", operator: "gte", value: "11/11/2013" }
                ]
            }
        ]
    }]
  )
})

Send a small demo project that reproduces the exception that you shared so we can investigate and advise you how to avoid the exception that you have on your side.

Kind 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
Karl
Top achievements
Rank 1
answered on 03 Dec 2013, 09:33 AM
My apologies, what appeared to be a kendo error was in fact an error elsewhere.  I have resolved this now.  Many thanks for your help.
Tags
Data Source
Asked by
Karl
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Karl
Top achievements
Rank 1
Share this question
or