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

Filtering data source dynamically

2 Answers 679 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Gabriel
Top achievements
Rank 1
Gabriel asked on 15 Jan 2012, 06:31 AM
Instead of listing the filters in code like this:
dataSource.filter([    
{ field: "orderId", operator: "neq", value: 42 },    
{ field: "unitPrice", operator: "ge", value: 3.14 }
]);

I would like to add them from a JSON array. How would I go about this? When I try, all I get is one filter being appended to the query string not in the correct format, rather looking like this:
filter[filters][]

instead of:
filter[filters][0][field]
filter[filters][0][operator]
filter[filters][0][value]

2 Answers, 1 is accepted

Sort by
0
Accepted
Andrew
Top achievements
Rank 1
answered on 15 Jan 2012, 04:56 PM
Not sure about the JSON bit, but I had luck using a straight forward array.  Maybe you need to cycle thru the JSON  and build an array then set using that?

 var A = new Array();
 A.push({ field: "somefld", operator: "eq", value: "Foo" });
 A.push({ field: "somefld", operator: "eq", value: "Fee" });
 A.push({ field: "someotherfld", operator: "eq", value: "Fi" });
 dataSource.filter(A);

0
Gabriel
Top achievements
Rank 1
answered on 15 Jan 2012, 10:06 PM
Thanks Andrew. I had my Javascript arrays screwed up.
Cheers.
Tags
Data Source
Asked by
Gabriel
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Gabriel
Top achievements
Rank 1
Share this question
or