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

Refresh transport.data on the fly

3 Answers 581 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
BobDev
Top achievements
Rank 1
BobDev asked on 08 Nov 2011, 11:10 AM
Hi,

I am having trouble figuring out how to get the data source to re-read its data. This is in context of a grid being bound to the data source.

I can set a new filter on the the data source and it will re-get, issue a change event which updates the grid. But filters seems to be limited to the columns in the data source.

In my situation I need to change a transport.data parameter (I am also using parameterMap) for the new data.

I tried:
mygrid.dataSource.transport.read({ data: { some_param: "some_data" }});

In this case "some_param" shows up in parameterMap and I can pass it on as a parameter. The dataSource then re-gets again but does not issue a change event, so the grid is not updated.

I was expecting to be able to change transport options and then do something like dataSource.Refresh() which in turn would re-get and trigger the change event.

OR provide some custom data in a filter that is related to the columns in the data.

Another way to put is allow client filtering, but go to the server if the filter column does not exist locally.

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Nov 2011, 02:22 PM
Hello Bobdev,

In order to force DataSource to retrieve its data, you may use the read method. Note that in case of remote binding configuration this will issue an request to the server.
Regarding the passing parameters to through the transport, instead of a static value you may assign a function which to return the value:

var productsDataSource = new kendo.data.DataSource({
    serverFiltering: true,
    transport: {
        read: {
            url: "products.html",
            data: {
                foo: function() {
                    return "bar"; // calculate the param value
                }
           }
        }
    }
});
 
$("a").click(function() {
    productsDataSource.read();
});

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dmitry
Top achievements
Rank 1
answered on 05 Dec 2011, 10:54 AM
Hello,
I use AJAX-enabled WCF service and I would like to do something like this:
        this._service.GetFilterOperations(columnType,
                            function (result) {
                                var ddl = _this._cbFunctions.data("kendoDropDownList");
                                ddl.dataSource = new kendo.data.DataSource({ data: result });
                                _this._condition = _this._getCondition();
                                _this._element.trigger("filterConditionChanged", [_this, _this._condition]);
                            });

where this._service is a client instance of my service:
[ServiceContract(Namespace = "UpeServices")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UpeService
    {
        [OperationContract]
        public string[] GetFilterOperations(string columnType)
        {
            return new FilterFunctionsDictionary()[columnType];
        } 
    }
Is that possible? I would not want to use an asmx service in project.
0
Dmitry
Top achievements
Rank 1
answered on 05 Dec 2011, 11:24 AM
My apologies, I should have made some research before posting. Code below should do the work:
this._service.GetFilterOperations(columnType,
                            function (result) {
                                var data = [];
                                for (var key in result) {
                                    data.push({ "text": result[key].Value, "value": result[key].Key});
                                };
                                var ddl = _this._cbFunctions.data("kendoDropDownList");
                                ddl.dataSource.data(data);
                            });
Tags
Data Source
Asked by
BobDev
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or