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

Custom add row not working

4 Answers 936 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Coolasia
Top achievements
Rank 1
Coolasia asked on 09 Feb 2017, 01:00 PM

Hi,

In my project I am using the custom add row functionality where the row is a row template, I am  using the grid.dataSource.add(dataitem) method to add the model data for the empty row as I have to send the data from server to the empty row. Below are the problems I am facing

1. When I do grid.dataSource.add(dataitem) the row is always getting at the bottom of the table.

2. After adding the row I am intializing the controls like (datetimepicker,timepicker,select2 etc) for the added row, this works fine if I add row for first time. When I click again to add row with grid.dataSource.add(dataitem) the first row is loosing its initialization like datetimepickers, select 2 and others. So when I debug I found that every time I click add new row with dataSource.add() the table is again calling the rowTemplate function for all the data items in the datasource so the control initializations are getting destroyed.

So can you please help how to resolve those two. 

4 Answers, 1 is accepted

Sort by
0
Coolasia
Top achievements
Rank 1
answered on 11 Feb 2017, 10:08 AM

Can somebody please help in this.

 

0
Dimiter Topalov
Telerik team
answered on 13 Feb 2017, 07:22 AM
Hi,

You can use the dataSource.insert() method instead of the add() one to provide the index the new item should be inserted in.

As for the second issue, the most straightforward approach would be to handle the Grid dataBound event, and initialize all required Kendo UI widgets from the respective already rendered elements in the row templates.

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Coolasia
Top achievements
Rank 1
answered on 13 Feb 2017, 09:48 AM

For the second suggestion where you mention to re initalize all the controls again for all the rows in grid, does this affect the performance if I already have 10000 rows with controls already initialized and when on new add row click again in the databound I have re initialize all the controls in 10000 rows as well as for the new row?

Also one more question as I am using row template can I use the grouping for the grid.

0
Dimiter Topalov
Telerik team
answered on 14 Feb 2017, 10:12 AM
Hi,

It is highly recommended to use either paging or virtual scrolling for Grids with many records (paging is sensible even with not so many records when the Grid rows' combined height is greater than the one of the viewport). Then only the currently rendered number of rows will be recreated (along with their widgets).

Creating the widgets in the dataBound event should not affect performance, as when this event is raised, this means that the Grid is rebound and rerendered anyway.

As for your second question, combining a row template with the Grid grouping functionality is possible, but a TD element with the "k-group-cell" class should be added to each row (the Grouping with row templates section):

http://docs.telerik.com/kendo-ui/controls/data-management/grid/walkthrough#configuration-Grouping

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Coolasia
Top achievements
Rank 1
Answers by
Coolasia
Top achievements
Rank 1
Dimiter Topalov
Telerik team
Share this question
or