Refreshing the Datasource of a Grid not working

Thread is closed for posting
15 posts, 0 answers
  1. mvbaffa
    mvbaffa avatar
    102 posts
    Member since:
    Dec 2006

    Posted 30 Jul 2012 Link to this post

    Hi,

    I have a Grid that works OK when I first show it. But when I try to change the Datasource with myGrid.dataSource.data(ds) it does not work.

    When "ds" is a simple json object containing a simple list of objects the Grid is updated correctly, but when "ds" is a dataSource with oher config parameters defined, the grid is cleared, as the datasource had no record.

    How can I solve it, will I have to destroy the Grid and create it again ???

    Can you help me. ???
  2. Gary
    Gary avatar
    18 posts
    Member since:
    Jun 2012

    Posted 02 Aug 2012 Link to this post

    I had a similar issue, not sure if this will help in your case or not.

    I had one ajax call that returned 4 different data sets.  I would then create a DataSource for each of those data sets:

    ds1 = new kendo.data.DataSource({
        data: dataFromAjax.Summary,
        ... other setup here ...
    });


    I would then replace the grid dataSource with that and call refresh:

    myGrid.dataSource = ds1;
    myGrid.refresh();


    That did not work.  The missing step is you still need to call read on the dataSource:

    myGrid.dataSource = ds1;
    ds1.read();
    myGrid.refresh();


    That worked for me, maybe that will help you out.

    Gary
  3. Kendo UI is VS 2017 Ready
  4. mvbaffa
    mvbaffa avatar
    102 posts
    Member since:
    Dec 2006

    Posted 02 Aug 2012 Link to this post

    Thanks Gary, I will check it out.
  5. Boris
    Boris avatar
    24 posts
    Member since:
    Jun 2012

    Posted 02 Aug 2012 Link to this post

    Try this:
            var grid = $("#gri").data("kendoGrid");
            grid.dataSource.data(ds1);
            grid.refresh();

    if you want to manually set it.

    Or you could do this:

    $("#grid").data("kendoGrid").dataSource.read();
    

    to re-read from server...
  6. mvbaffa
    mvbaffa avatar
    102 posts
    Member since:
    Dec 2006

    Posted 07 Aug 2012 Link to this post

    Hi,

    It really worked thanks. When I execute this:
    dsAtivos.getObject().read();
    dsAtivos.getObject().refresh();

    The Grid is updated but another problem occured whith the pagination. When I first show the Grid the pagination works perfectly but after the update above when I try to move to a different page I receive the error:
    Microsfot JScript runtime error: DOM Exception: NOT_FOUND_ERROR (8)

    And an error is maked ant kendo.min.all here:
    c.table[0].replaceChild(i,c.tbody[0])

    Hiow can I solve this ?

    Thanks in advance

  7. Gary
    Gary avatar
    18 posts
    Member since:
    Jun 2012

    Posted 07 Aug 2012 Link to this post

    That is interesting, I wasn't using a pager so I didn't run into that issue.  Hopefully someone else will chime in or someone from Telerik will reply.
  8. Rohit
    Rohit avatar
    3 posts
    Member since:
    Mar 2012

    Posted 07 Aug 2012 Link to this post

    I have the same problem. i think the event handlers does not get associated when we do refresh and read
  9. Gareth
    Gareth avatar
    1 posts
    Member since:
    Aug 2012

    Posted 07 Aug 2012 Link to this post

    I had the problem of the ajax datasource is not being called after the first load. You need to set ajax cache = false.

     $.ajaxSetup({ cache: false }); 
  10. mvbaffa
    mvbaffa avatar
    102 posts
    Member since:
    Dec 2006

    Posted 08 Aug 2012 Link to this post

    Hi,

    I need an urgent help.

    As I told you I can refresh the grid but a problem occured whith the pagination. When I first show the Grid the pagination works perfectly but after the update when I try to move to a different page I receive the error:

    Microsfot JScript runtime error: DOM Exception: NOT_FOUND_ERROR (8)

    And an error is maked ant kendo.min.all here:
    c.table[0].replaceChild(i,c.tbody[0])

    But I have discovered that the same error occurs when I try to sort a column of the grid.

    Please, you developers from Telerik, this is really urgent. I cannot use the grid like this. I need your help.

    Thanks

  11. Gary
    Gary avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2012 Link to this post

    You should open a support ticket.  I have found that to be helpful.  If you do, please come back here and post the answer for everyone.

    Gary
  12. Kumarasen
    Kumarasen avatar
    3 posts
    Member since:
    Aug 2012

    Posted 08 Aug 2012 Link to this post

    I am having a lot of problems trying to reinitialise the datagrid when the datasource has changed.

    For example, I have a component that creates the dataset on 1 tab, and the DevX grid on the other.

    It works fine the first time it is used, but I want to be able to change the query and subsequent dataset and completely rejig the grid accordingly. I thought this would be simple but it is proving to be difficult. Please prove me wrong.

    As an example is say I have a query that outputs 2 rows of data:

    Select TEST.NAME, TEST.DESCRIPTION, TEST.OCCUPATION
    From TEST

    Then I go back and change the query to:

    Select TEST.NAME, TEST.DESCRIPTION
    From TEST

    and reset the datasource, the occupation column is still present on the grid, with no data.

    I am setting the grid's datasource in this way:

    adapter.Fill(dataset, "QueryResult")

    dvxDataGrid.DataSource = dataset.Tables("QueryResult")

    I have tried everything I can think off from:  

    dvxDataGrid.MainView.LayoutChanged() 

    dvxDataGrid.MainView.BeginInit() 

    dvxDataGrid.MainView.PopulateColumns() 

    dvxDataGrid.MainView.RefreshData()

    dvxDataGrid.ForceInitialize() 

    dvxDataGrid.DataSource = Nothing before reset 

    dvxDataGrid.Dispose()

    .etc. etc. in a variety of configurations with no luck...

    Any help would be much appreciated? Do I need to build a completely new view?

    Plans for a Chicken Coop 

  13. Rohit
    Rohit avatar
    3 posts
    Member since:
    Mar 2012

    Posted 08 Aug 2012 Link to this post

    So I finally solved this problem.
    Here was what my problem was:
    1. On first pageload I made an ajax call.
    2. I associated the data returned as datasource of a grid.
    3. This grid had sorting and pageing enabled

    Now when the user clicks next the whole page gets new record so the grid had to be refreshed
    1. I make ajax call again.
    2. I associated new data with grid's data source.
    3. I called grid.dataSource.read();
                    grid.refresh();
    The data got refreshed however the sorting and pageing was not working at all.

    Solution:
    I re created the grid. However before you do so you have to destrot the old one.
    Here is what I did on Next click:
    1. called ajax and got data.
    2. destroyed the old grid by calling:
            $('#grvScript').val(''); (here grvScript is the div which we use for grid)
            $('#grvScript').html('');
    3. Then i recreate the grid by calling:
     $('#grvScript').kendoGrid({ "you code here"});

    This solved my problem. Hope it works for you  guys.
  14. mvbaffa
    mvbaffa avatar
    102 posts
    Member since:
    Dec 2006

    Posted 09 Aug 2012 Link to this post

    Hey Rohit,

    It worked perfectly !!!

    Thank you very much for your help.
  15. Muhammad
    Muhammad avatar
    4 posts
    Member since:
    Nov 2010

    Posted 08 Nov 2012 Link to this post

    is working in the "update" add this code in the transport:
                   complete: function(e) {

    }


    thanks a lot
     or

    update: {
                            url: _updateURL,  
    //                        dataType: "jsonp",
                            type: "POST",
                            complete: function(e) {
                            $("#grid").data("kendoGrid").dataSource.read(); 
                            }                        
                        },
  16. Insomniac82
    Insomniac82 avatar
    18 posts
    Member since:
    Aug 2008

    Posted 04 Oct 2013 Link to this post

    How can I refresh a detail template grid's datasource when the detail grid is expanded?
Back to Top
Kendo UI is VS 2017 Ready