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

Dynamically change grid data in javascript

3 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tong
Top achievements
Rank 1
Tong asked on 30 Mar 2016, 07:47 PM

In javascript, based on user selection, I want to dynamically change grid datasource, reading data from controller. sample codes below

        var data = $('#MarketDrivers').data('kendoTreeView').dataItem(e.node);
        //chart2.setDataSource(ds2);

        var gd = $("#grid").data("kendoGrid");
        var ds3 = new kendo.data.DataSource({
            transport: {
                read: {
                    type: "POST",
                    url: "/Blotter/getIDView",
                    data: { factorID_: data.id },
                    dataType: "jsonp"
                }
            }
        });
        gd.setDataSource(ds3);

 

This controller action will be triggered, but the grid will show "No items to display".  My controller action is like below...

 

        public ActionResult getIDView([DataSourceRequest] DataSourceRequest request, int? factorID_)
        { 
            List<PersonView> li = new List<PersonView>();
            //some code here...
            return Json(li.ToDataSourceResult(request));
        }

Anyone knows what's wrong here? Thanks

 

 

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 01 Apr 2016, 12:24 PM

Hello Tong,

It is not exactly clear what is the real reason for the unexpected behavior. Is the controller hit in this case? You could inspect the network tab of the browsers developer tools to assure that the request was executed as expected and also the console for JavaScript errors. If the problem is still persisting you could send us an isolated runnable example, so we could inspect the case locally and assist further.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Tong
Top achievements
Rank 1
answered on 01 Apr 2016, 01:09 PM

Thanks Dimiter. I do exact the same for chart data and works...Not sure how grid data is different. (controller got called when debug)

Anyway, after search this forum, I changed my approach to get all data first and then filter later (don't change data source). It works. I am good for now and can live with it. 

Thanks

0
Dimiter Madjarov
Telerik team
answered on 01 Apr 2016, 01:55 PM

Hello Tong,

Thank you for the update.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Tong
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Tong
Top achievements
Rank 1
Share this question
or