Refreshing the Datasource of a Grid not working
1 Answer 2494 Views
This question is locked. New answers and comments are not allowed.
mvbaffa
Top achievements
Rank 1
mvbaffa asked on 30 Jul 2012, 12:47 PM
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. ???
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
- by
Gary
Top achievements
Rank 1
on 02 Aug 2012, 04:49 PM
Thanks Gary, I will check it out.
- by
mvbaffa
Top achievements
Rank 1
on 02 Aug 2012, 08:19 PM
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...
- by
Boris
Top achievements
Rank 1
on 02 Aug 2012, 08:31 PM

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

- by
mvbaffa
Top achievements
Rank 1
on 07 Aug 2012, 02:53 PM
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.
- by
Gary
Top achievements
Rank 1
on 07 Aug 2012, 02:56 PM
I have the same problem. i think the event handlers does not get associated when we do refresh and read
- by
Rohit
Top achievements
Rank 1
on 07 Aug 2012, 07:33 PM
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 }); 
- by
Gareth
Top achievements
Rank 1
on 08 Aug 2012, 12:34 AM
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

- by
mvbaffa
Top achievements
Rank 1
on 08 Aug 2012, 08:51 PM
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
- by
Gary
Top achievements
Rank 1
on 08 Aug 2012, 09:09 PM

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 

- by
Kumarasen
Top achievements
Rank 1
on 08 Aug 2012, 10:20 PM

1 Answer, 1 is accepted

Sort by
0
Rohit
Top achievements
Rank 1
answered on 08 Aug 2012, 11:43 PM
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.
Hey Rohit,

It worked perfectly !!!

Thank you very much for your help.
- by
mvbaffa
Top achievements
Rank 1
on 09 Aug 2012, 01:31 PM
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(); 
                        }                        
                    },
- by
Muhammad
Top achievements
Rank 1
on 08 Nov 2012, 08:34 AM
How can I refresh a detail template grid's datasource when the detail grid is expanded?
- by
Insomniac82
Top achievements
Rank 1
on 04 Oct 2013, 02:18 PM
Tags
Grid
Asked by
mvbaffa
Top achievements
Rank 1
Answers by
Rohit
Top achievements
Rank 1
Share this question
or