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

datasource.filter(...) causes a request

4 Answers 1492 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Gordon
Top achievements
Rank 1
Gordon asked on 02 Oct 2014, 12:39 PM
Hi to all,

I am using your datasource for accessing an odata service. I am changing the filter when the selected row of a grid changes.
Therfore I am using the ds.filter() method.
When I check the traffic to the http endpoint via fiddler I have seen that just setting the filter fires a request to the server.
OK I thought, lets spare out the fetch method and consume the data right after setting the filter because the request has been implicitly made by the filter method.
But the data has not been updated, this is because the request will be made async I think...

So I have to call fetch and use a callback to be in sync with the request\response.

Is it possible to supress the request when setting the filter via filter() method? Otherwise these request will be made twice on every change...

--- init of data source
if (t.quickViewDataSource == null) {
                console.log("init quick view data source...");
                t.quickViewDataSource = new kendo.data.DataSource({
                    type: "odata",
                    transport: {
                        read: {
                            url: "https://someone.com/fis/odata/mydata",
                            dataType: "json"
                        }
                    },
                    sort: { field: "Released", dir: "desc" },
                    schema: {
                        data: function(data) {
                            return data.value;
                        },
                        total: function(data) {
                            return data["odata.count"];
                        },
                        errors: function(data) {

                        },
                        model: {
                            fields: {
                                FlightId: { type: 'number', nullable: false },
                                InfoType: { type: 'string' },
                                Displayname: { type: 'string' },
                                Title: { type: 'string' },
                                Released: { type: 'datetime', nullable: false },
                                Size: { type: 'number' },
                                DbTimeStamp: { type: 'datetime', nullable: false },
                                Format: { type: 'string' },
                                Identifier: { type: 'string', nullable: false },
                                OfpAltnNo: { type: 'number' }
                            }
                        }
                    },
                    filter: {
                        logic: "and",
                        filters: [
                            { field: "FlightId", operator: "eq", value: -1 },
                            { field: "InfoType", operator: "eq", value: "X" }
                        ]
                    },
                    pageSize: 1,
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                });
                t.quickViewDataSource.fetch();
            }

--- code that uses the datasource
...
var dataItem = t.mainGrid.dataItem(selected);
                var flightId = dataItem.Id;

                t.quickViewContent("LOADING...");

                t.quickViewDataSource.filter(
                    [
                        { field: "FlightId", operator: "eq", value: flightId },
                        { field: "InfoType", operator: "eq", value: type }
                    ]
                );

               t.quickViewDataSource.fetch(function () {
                    var rows = t.quickViewDataSource.data();
                    if (rows.length > 0) {
                        var row = rows[0];
                        
                        var dataUri = t.globals.baseUriBinaryData + row.Identifier;
                        $.get(dataUri).done(function(data) { t.quickViewContent(data); }).fail(function(error) { t.quickViewContent("failed to load data from server: " + error); });
                    } else {
                        t.quickViewContent("NO DATA AVAIABLE");
                    }
                });

4 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 02 Oct 2014, 01:41 PM
Hi Gordon,

Have you tried using the query() method? It will both read the data from the remote service and you can pass the filter expression. Here is the documentation about it:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-query

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Gordon
Top achievements
Rank 1
answered on 02 Oct 2014, 02:12 PM
Thanks a lot! This works fine.
0
Gordon
Top achievements
Rank 1
answered on 02 Oct 2014, 04:10 PM
I am sorry... I was lazy and have not tested it correctly...
The problem regarding the async loading and getting old data when accessing the data from the datasource immediatly after calling query\filter is the old data from the request done before.
Is query\filter promise ready, are there callbacks I can use or are there any other possibilities to read the data from the source after the query is done?

Kind regards
Gordon
0
Kiril Nikolov
Telerik team
answered on 03 Oct 2014, 08:06 AM
Hello Gordan,

What you can do is to attach a change event handler, for the dataSource change event, so when this change is fired you will be sure that the new data is fetched. More documentation is available here:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#events-change

Regards,
Kiril Nikolov
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
Gordon
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Gordon
Top achievements
Rank 1
Share this question
or