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

Data Source new request after filter

1 Answer 762 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Larissa
Top achievements
Rank 1
Larissa asked on 09 Mar 2016, 06:02 PM

I have a page with a combo box to select a type and two date pickers (start date and end date).

The user selects a type, both dates and clicks on a load button.

The request retrieves data from all types in this date range.

And I'm using a filter in a data source to display on a grid only the records of the type selected by the user (relevant information of the data response).

Code:

$("#loadButton").kendoButton({
    click: loadGrid
});
 
var loaded = false;
function loadGrid(e) {
    if (type) {
        if (loaded) {
            var grid = $("#grid").data("kendoGrid");
            grid.wrapper.empty();
            grid.destroy();
        }
 
        $("#grid").kendoGrid({
            scrollable: false,
            editable: false,
            autoBind: false,
            dataSource: dataSource,
            columns: [], // omitted
        });
 
        var typeString = kendo.toString(type);
        $("#grid").data("kendoGrid").dataSource.filter({
           logic: "or",
           filters: [
               { field: "type", operator: "startswith", value: "-1" },
               { field: "type", operator: "startswith", value: typeString }
           ]
        });
        loaded = true;
    } else {
       e.preventDefault();
       alert("Select a type!");
    }
}
 
function getData() {
        return {
            type: type,
            startDate: kendo.toString(pickerStart.value(), "yyyy-MM-dd"),
            endDate: kendo.toString(pickerEnd.value(), "yyyy-MM-dd")
        };
    }
 
var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: url",
                dataType: "json",
                data: getData
            }
        },
        schema: {
            total: "total",
            data: "list"
        },
        group: { field: "date" }
    });

 

If the user selects a different type, the data in the data source is filtered and it works fine.

The problem is that, if the user selects a different date, a new request should be done to get the new data and then filtered by type as it already does.

Right now, if the user selects a different type, the data is filtered, but if the user selects a different date, nothing happens.

Can someone tell how to handle this situation?

Am I using it wrong?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 12 Mar 2016, 08:14 AM
Hello Larissa,

Generally speaking, the datasource component will make additional request if the server filtering is enabled: As you can see the source sends updated fields to the server on filter.

If you would like to use client filtering, then you will need to force the widget to read the new data and then to filter it.

Regards,
Georgi Krustev
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
Larissa
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or