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

Filter on datasource That doesn't work

1 Answer 859 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
guillaume
Top achievements
Rank 1
guillaume asked on 14 Nov 2013, 05:21 PM
Hi !

i've got a problem to make my filter works,.
i'm doing a request to a file that contains some json code see below:

[
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058500","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058501","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058502","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058503","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058504","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058505","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058506","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058507","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058508","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"},
{"Adresse1":"1 RUE HERMARY", "CP":"62620","ID":"058509","Lat":"50,4597886","Long":"2,6139708","Nom":"PRESSING","Pays":"FR","Photo":"http://www.mondialrelay.fr/img/dynamique/pr.aspx?id=FR065358","Ville":"BARLIN"}
]
and here is my request :

function getDataFromFileById(fl){
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "./data.json",
                dataType: "json",      
            },
        },
        filter: { field: "ID", operator: "eq", value: fl }
    });
    console.log(dataSource);
    return (dataSource);
}
when i'm using this function without any filter, it works perfectly.
i read the doc and i did try to add some filter by the same way and i get an object but without my data ...
by the way the 'fl' parameter i use as filter is a number (058500).
am i doing something bad ? 
thanks for reading and answering,
best regards :)

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Nov 2013, 08:07 AM
Hello,

 The problem is caused by the fact that the "ID" field in the JSON file is a string and you try to filter it as a number.
You can solve it by:

  • removing the quotes to make the ID field a real number 
  • declaring a field with type number:
    var dataSource = new kendo.data.DataSource({
        schema: {
          model: {
            fields: {
               ID: { type: "number" }
            }
          }
        },
        transport: {
             read: {
                 url: "./data.json",
                 dataType: "json",     
             },
          },
          filter: { field: "ID", operator: "eq", value: fl }
    });

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
guillaume
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or