Refresh grid after insert/update

3 Answers 6585 Views
Grid
Raja
Top achievements
Rank 1
Raja asked on 22 Dec 2015, 08:15 PM

Hi,

I have a grid that will create multiple records in the database on Create/Update of any record in the grid. I would like to refresh the grid once the create/insert is complete so that all the newly created records will be visible to the user. How can I do that?

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Topalov
Telerik team
answered on 23 Dec 2015, 03:57 PM
Hi Raja,

You can listen for the save or saveChanges event of the Grid (depending on the edit mode you are using) and attach a dataBound handler to the Grid, which will be executed only once. Refresh the Grid dataSource in this dataBound handler with the .read() method of the DataSource. This will get the current records from the database and re-render the Grid using the latest data:

function onGridSave(e) {
  e.sender.one("dataBound", function() {
    e.sender.dataSource.read();
  });
});


Regards,
Dimiter Topalov
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
0
Dan
Top achievements
Rank 1
Veteran
answered on 21 Jul 2020, 09:38 PM

In case anyone else is wondering what working code, based on the above comment, looks like. Here is what is working for me:

This code works for both the Create and Update Grid events.

function onGridEdit(e) {
    e.sender.one("dataBound", function (e) {
        e.sender.dataSource.read();
    });
}
 
function bindDataAndRefresh(e) {
    var grid = $("#upcoming-grid").data("kendoGrid");
    grid.bind("dataBound", onGridEdit(e));
}
 
$(document).ready(function () {
    var grid = $("#upcoming-grid").data("kendoGrid");
    grid.bind("save", bindDataAndRefresh);
});
Petar
Telerik team
commented on 23 Jul 2020, 09:56 AM

Hi Dan,

Thank you for sharing the code that worked on your end with the community! Your post will surely help someone in the future. 

Regards,
Petar
Progress Telerik

0
Pascal
Top achievements
Rank 1
answered on 26 Feb 2021, 08:52 AM

> Your post will surely help someone in the future.

It did. Thanks Dan!

Manoj
Top achievements
Rank 1
commented on 30 Jan 2024, 05:58 PM

Thanks Dan for sharing this post, It helped me a lot. thanks.
Tags
Grid
Asked by
Raja
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Dan
Top achievements
Rank 1
Veteran
Pascal
Top achievements
Rank 1
Share this question
or