Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo DataSource: How to set filters before fetch without sending two httprequests

Environment:

  • kendo version: 2013.1.319
  • dataSource:

    productsDataSource = new kendo.data.DataSource({
        type: "odata",
        transport: {
            read: "http://www.mydomain.com/odata.svc/products",
            dataType: "json",
            contentType: "application/json"
        }
        schema: {
            type: "json",
            data: function(data){
                return data.value;
            },
            total: function(data){
                return data['odata.count'];
            },
            model: product
        },
        pageSize: 50,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    });
    
  • Get data:

    productsDataSource.filter([{ field: "Id", operator: "eq", value: 5 }]); //this will send an httprequest

    productsDataSource.fetch(function (e) { tempDataStorage = e.items; //more logic to dealing with the data; });

  • problems:

    1. need to use the fetch method of the dataSource for data processing(widgets initialization, data binding...etc);
    2. avoid sending two httprequests when setting filters before fetch;
    3. the filter condition need to be changed at runtime.
like image 993
Dean Avatar asked Mar 26 '13 10:03

Dean


1 Answers

productsDataSource._filter = { logic: 'and', filters: [
{ field: "Id", operator: "eq", value: 5 }]};

I've found this to work. Set the internal property to a full filter object. You can then call fetch afterwards. I've not yet found a way to change the page size without triggering a fetch however.

like image 182
Daniel Revell Avatar answered Sep 21 '22 21:09

Daniel Revell