Rebind and refresh dataSource on grid

Thread is closed for posting
5 posts, 0 answers
  1. David Edwards
    David Edwards avatar
    6 posts
    Member since:
    Aug 2009

    Posted 29 Nov 2012 Link to this post

    So I have a grid on a search page that I need to rebind on button click.

    here is my code.

    var sourceUrl = "Dynamic source url";

            var dataSource1 = new kendo.data.DataSource({
                type: "json",
                transport: {
                    read: sourceUrl
                },
                serverOperation: false,
                serverSorting: true
            });

            var grid = $("#grid").data("kendoGrid");

            grid.dataSource = dataSource1;

            grid.dataSource.transport.read();
            grid.dataSource.read();

            grid.refresh(); 


    This all happens on a button click event outside of the grid.  


    The problem is, is that the grid is not actually refreshing.  The data is being pulled back successfully, but it is not getting displayed.
    Since I have server sorting turned on on the grid, I clicked on one of the column headers and the data displayed properly.

    What is server sorting doing to the grid to refresh it that is different than what I am doing?
  2. Rosen
    Admin
    Rosen avatar
    3247 posts

    Posted 30 Nov 2012 Link to this post

    Hello David,

    Assigning the DataSource instance to Grid widget's dataSource field is not supported and will not work as expected. It is preferable to assign the DataSource during the databound widget declaration, or in cases where changing the DataSource is required, you may use setDataSource method of the widget. This way the widget will be able to attached to DataSource's notification events and correctly refresh its state when needed.

    Also note that calling read method of the DataSource is sufficient in order to repopulate the DataSource (which will automatically refresh the widget's content).

    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!
  3. David Edwards
    David Edwards avatar
    6 posts
    Member since:
    Aug 2009

    Posted 03 Dec 2012 Link to this post

    perfect.  Thanks for your help.  I had not seen the setDataSource() method.  
  4. Trushar
    Trushar avatar
    2 posts
    Member since:
    Nov 2016

    Posted 09 Dec 2016 Link to this post

    Hi I have similar issue but in my case filter is not getting refresh when result is changing in grid. can you put some light on this?
  5. Rosen
    Admin
    Rosen avatar
    3247 posts

    Posted 09 Dec 2016 Link to this post

    Hello Trushar,

    I'm afraid that I'm not able to tell what may caused such behavior judging from the provided information. 

    Due to the age of this thread I will ask you to open a separate support request in which to provide as much information about your scenario and the behavior you are facing as possible. Code snippets, a runnable test page demonstrating the issue will be welcomed. 

    Regards,
    Rosen
    Telerik by Progress
    Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Back to Top