Dynamically change grid data in javascript

4 posts, 0 answers
  1. Tong
    Tong avatar
    8 posts
    Member since:
    Feb 2016

    Posted 30 Mar Link to this post

    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

     

     

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 01 Apr Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Tong
    Tong avatar
    8 posts
    Member since:
    Feb 2016

    Posted 01 Apr in reply to Dimiter Madjarov Link to this post

    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

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 01 Apr Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready