Dealing with data which includes a field having an array of strings

2 Answers 75 Views
Data Query
nodsec
Top achievements
Rank 1
Iron
Iron
nodsec asked on 17 Aug 2022, 07:42 AM

Does exists any operator, which is able to filter all data values, where "X includes 1" ?

<script>
var dataSource = new kendo.data.DataSource({
  data: [
    { name: "Jane Doe", birthday: new Date(1983, 1, 1), x: [1, 2]},
    { name: "John Doe", birthday: new Date(1980, 1, 1), x: [2, 3]}
  ],
  filter: { field: "x", operator: "eq", value: 1 }
});
dataSource.fetch(function(){
  var view = dataSource.view();
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(view.length); // displays "1"
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(view[0]); // displays "Jane Doe"
});
</script>

Thanks a lot for an each help :-)

2 Answers, 1 is accepted

Sort by
0
Accepted
nodsec
Top achievements
Rank 1
Iron
Iron
answered on 17 Aug 2022, 09:20 AM

Solution: use operator: "contains" with "ignoreCase:false":

<script>
var dataSource = new kendo.data.DataSource({
  data: [
    { name: "Jane Doe", birthday: new Date(1983, 1, 1), x: ["aaa", "bbb"]},
    { name: "John Doe", birthday: new Date(1980, 1, 1), x: ["bbb", "ccc"]}
  ],
  filter: { field: "x", operator: "contains", value: "bbb", ignoreCase: false }
});
dataSource.fetch(function(){
  var view = dataSource.view();
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(view.length); // displays "1"
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(view[0]); // displays "Jane Doe"
});
</script>

Thanks a lot for an each help :-)

0
Filip
Telerik team
answered on 18 Aug 2022, 05:43 PM

Hi, Nodsec,

Using ignoreCase together with the contains operator should indeed filter the data values.

Let me know in case you need further assistance.

Regards,FilipProgress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Tags
Data Query
Asked by
nodsec
Top achievements
Rank 1
Iron
Iron
Answers by
nodsec
Top achievements
Rank 1
Iron
Iron
Filip
Telerik team
Share this question
or