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

how to append a row programmatically (not in edit mode)

6 Answers 632 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim R
Top achievements
Rank 1
Tim R asked on 08 Jan 2013, 07:16 PM
Every 30 seconds the app fetches freshened data (same schema model) from the server. Existing rows in the grid that have become "stale" are updated using dataItem.set( fieldname, value).  Existing rows that no longer exist on the server are deleted with grid.removeItem(row).   But addRow() puts the grid into (visual) edit mode.   Is there a way to insert a fully populated row (as distinct from a blank row) into the grid without rebinding the grid to the freshened dataset by way of dataSource.data( newFreshData)  which disrupts the UI state of collapsed/expanded groups?

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 10 Jan 2013, 09:29 AM
Hello Tim,

>> "Is there a way to insert a fully populated row (as distinct from a blank row) into the grid without rebinding the grid"

There is no officially supported way to do that. You can try adding the row by means of standard (or jQuery) DOM operations. But since the Grid will not be aware of this row, you may experience undesired side effects. For example, the Grid's "zebra" row styling below the new row will have to be readjusted.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tim R
Top achievements
Rank 1
answered on 10 Jan 2013, 12:16 PM
Dimo, thanks for confirming that there is no public API method to insert a row into the grid programmatically.  I will make a formal feature request. 
0
Tim R
Top achievements
Rank 1
answered on 10 Jan 2013, 12:46 PM
I have just now made the feature request in User Voice.  

In the meantime, I am wondering if it's possible to clone an existing dataItem, assign it a new UID, use dataItem.set(field, value) to change the cell values as needed, and then push() the new dataItem into the grid. _data array. I am assuming (correctly?) that the row would be treated as a new row if it has a different UID.  

EDIT: doesn't seem to be working as I'd hoped it might.


             
0
Dimo
Telerik team
answered on 10 Jan 2013, 04:01 PM
Hello Tim,

By design, new data items should be added to the datasource, which will then fire its change event and the Grid will be rebound. It seems that you want to do it the other way around by not using the public APIs, but I am afraid we cannot support such implementations.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tim R
Top achievements
Rank 1
answered on 10 Jan 2013, 04:50 PM
I have been searching  for some way to add a row that does not destroy the collapsed/expanded state of existing groups.  By default, when the Kendo grid binds to data, it re-expands all groups; dataSource.data( newFreshDataSameSchemaModel) expands all groups; dataSource .add( { ...} )  also expands all groups.

I would be happy to store and then reapply the collapsed/expanded state of groups myself, but we don't have groupCollapsed or groupExpanded events, and in any case the unique handle to the k-grouping-row is ephemeral. The UID changes when the grid is re-bound to data.

The ephemeral nature of the k-grouping-row's UID is why, in another request, I asked for a custom data attribute data-k-distinct-values for the k-grouping-row, so I would have a non-ephemeral unique handle that would allow me to find particular k-grouping-rows after data-binding has occurred.

The Kendo grid, as is, is not 100% amenable to real-time data refreshes.  Despite Ajax XHR, we might as well be doing postbacks if the grid is going to forget important things like the collapsed/expanded state of its groups when a row is inserted into the underlying dataSource.

P.S. I am using the word "non-ephemeral" to avoid using the word "persistent" because I don't need to store the UI state to disk. I simply need the UI state of groups to survive a real-time data-refresh or insertion of a row into the underlying dataSource.




0
Dimo
Telerik team
answered on 11 Jan 2013, 10:02 AM
Hi Tim,

What I can suggest you is to submit a feature request that persistent group state is supported by the Grid. If the demand for this functionality is high enough, we will consider implementing it.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Tim R
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Tim R
Top achievements
Rank 1
Share this question
or