This is a migrated thread and some comments may be shown as answers.

Adding Multiple Rows Performance

4 Answers 715 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith Pepling
Top achievements
Rank 1
Keith Pepling asked on 11 Aug 2013, 06:27 PM
I have my grid setup in batch edit mode.  I have a requirement for a user to add multiple rows to the grid which I have by prompting the user for how many new rows they want to add then looping through and calling addRow method.  The problem is that it doesn't scale very well.  Adding 10 rows seems to work fine but by the time you get to 50 it takes upwards of 30 seconds to add those rows.  Is there anything I can do to make this faster or delay the redrawing of the grid as I add rows?

4 Answers, 1 is accepted

Sort by
1
Accepted
Alexander Valchev
Telerik team
answered on 12 Aug 2013, 12:38 PM
Hello Keith,

By design the dataSource does not provide an opportunity for inserting multiple records via one operation. The performance is low, because each time when you add row through the addRow method, the DataSource throws its change event which forces the Grid to refresh and re-paint the content.

To avoid the problem you may try to modify the data of the DataSource manually.
var grid = $("#grid").data("kendoGrid");
var data = gr.dataSource.data().toJSON(); //the data of the DataSource
 
//change the data array
//any changes in the data array will not automatically reflect in the Grid
 
grid.dataSource.data(data); //set changed data as data of the Grid


Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Keith Pepling
Top achievements
Rank 1
answered on 12 Aug 2013, 12:52 PM
That works perfect.  Using this technique I could easily add a 1000 new rows in a second.
0
Keith Pepling
Top achievements
Rank 1
answered on 12 Aug 2013, 01:05 PM
I have noticed one issue.  Once I add the data back in this way it sees all the records as edits instead of these new records as inserts.  How can I flag the new records as such?
0
Keith Pepling
Top achievements
Rank 1
answered on 12 Aug 2013, 01:27 PM
The records not being flagged as new was actually unrelated to this and was something else I was doing that caused this.
Tags
Grid
Asked by
Keith Pepling
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Keith Pepling
Top achievements
Rank 1
Share this question
or