Change datasource url on Grid

10 posts, 1 answers
  1. Tycho
    Tycho avatar
    12 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2012 Link to this post

    Hi,

    I've got a dropdown and a grid. The idea is to change the data displayed in the grid depending on the selection made in the dropdown.
    The datasource uses a json service. When the page is loaded the grid is filled with the data from the json service. After changing the selection in the dropdown the transport url is changed according to the alert. But capturing the network traffic reveals that the original url is called instead of the one with the new parameter. 

    The html excerpt:
    <input id="ddlFacility" />
     
    <div id="SiteOverviewTabStrip">
                <ul>
                    <li class="k-state-active">Regional dashboard</li>
                    <li>Production summary</li>
                </ul>
                <div class="placeholder table">
                    <div id="regionalGrid">
                    </div>
                </div>
                <div class="placeholder graph">
                    <div id="productionGrid">
                    </div>
                </div>
    </div>


    The script:
    // bind to the change event and update the data source url
     var ddlFacility = $("#ddlFacility").data("kendoDropDownList");
    ddlFacility.bind("change", function () {
         var grid = $("#regionalGrid").data("kendoGrid");
         grid.dataSource.options.transport.read.url = "/_layouts/SharePoint.Services/ProxyService.svc/GetFacilityRegionalData?origin=" + this.value();
     
      grid.dataSource.read();
          grid.refresh();
      alert(grid.dataSource.options.transport.read.url);
    });


    Any suggestions?

    Kind regards,
    Tycho
  2. Answer
    Joel
    Joel avatar
    78 posts
    Member since:
    Oct 2012

    Posted 17 Jan 2012 Link to this post

    You have transport and options reversed. Here's what you want set
    dataSource.transport.options.read.url = "/_layouts/SharePoint.Services/ProxyService.svc/GetFacilityRegionalData?origin="this.value(); 


    Joel
  3. Kendo UI is VS 2017 Ready
  4. Tycho
    Tycho avatar
    12 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2012 Link to this post

    Thanks! That did it.
  5. Tycho
    Tycho avatar
    12 posts
    Member since:
    Dec 2011

    Posted 25 Jan 2012 Link to this post

    Is there a way to update the columns after changing the datasource on a grid?
    I'm changing the url to another json call that returns other data so i would like to update the column names.

    I tried the following but that didn't update the column names. 
    var grid = $(gridname).data("kendoGrid");
    grid.columns =[ { title: "NewNameColumn1" },{ title: "Column 2" },{ title: "Column 3" }] ;
    grid.refresh();
  6. Joel
    Joel avatar
    78 posts
    Member since:
    Oct 2012

    Posted 26 Jan 2012 Link to this post

    Hmm, interesting ... I've wondered about this in the past. I haven't tried it as yet but I'm willing to bet the only way to do this right now is to reconfigure/build the entire grid.
  7. Tycho
    Tycho avatar
    12 posts
    Member since:
    Dec 2011

    Posted 27 Jan 2012 Link to this post

    Would you happen to have an example on how to rebuild/reconfigure a grid ?

    I've tried adding a placeholder div around the grid, call $('PlaceHolder').empty(), append a new div and create the grid again, but can't get it working.
  8. Rahul
    Rahul avatar
    11 posts
    Member since:
    Dec 2011

    Posted 02 Feb 2012 Link to this post

    wow thanks guys, this kept me hooked up for a while. Works perfect. thanks tycho and Joel !
  9. Shaun
    Shaun avatar
    1 posts
    Member since:
    Mar 2015

    Posted 27 Mar 2015 in reply to Joel Link to this post

    Thanks for this. 
  10. Mohammed
    Mohammed avatar
    1 posts
    Member since:
    Jan 2016

    Posted 12 Aug in reply to Joel Link to this post

    this is not working bcz datasource.transport does not exist.
  11. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 18 Aug Link to this post

    Hello Mohammed,

    Please open a separate thread with more details for your case.

    Without a reproduction case it's hard to tell if the problems you're experiencing are related to the discussion here.

    Regards,
    T. Tsonev
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready