Bumper
Bumper

Reputation: 387

Display multiple new rows in Kendo Grid

I am doing an inline add using Kendo Grid, but on the server side I am actually creating multiple records. The DataSourceRequest sends back all the newly created rows, but only one is added to the grid. The other added records may not show up in the grid at all until the grid is forced to query for the data again.

Is there a way for me to add multiple rows at once?

If not, is there a way to re-query the data and put all newly added models at the top?

In my controller function that creates the new records, I am returning the following. "models" contains all of the newly created records:

return this.Json(models.ToDataSourceResult(request, this.ModelState), JsonRequestBehavior.AllowGet);

I also have a similar issue when updating a row since the server may actually update multiple rows. Since "models" contains multiple models, the first one in the list may or may not be the actual model selected to be updated, so sometimes a different edited model will replace the model that was selected to be updated in the grid.

Thanks, Rob

Upvotes: 0

Views: 1385

Answers (1)

Bumper
Bumper

Reputation: 387

I ended up using the kendo grid datasource insert method to add any records returned by my controller that were not already in the grid. I did this in the RequestEnd event for the datasource.

In order for this to work for inline adds, I needed to make sure the first model in the list returned by the controller was always the model being added by the grid. For some reason the initial model being added does not have an ID until the dataBinding event is reached which occurs after the RequestEnd event. So on adds, I simply ignore the first model in the results because it is already in the grid.

Also, when editing rows that are manually inserted into the datasource and then cancelling the edit, the grid removes them from the datasource. I had to block this using the preventDefault() function in the DataBinding event when a "remove" action was encountered directly after editing a row that I manually inserted into the datasource.

Upvotes: 2

Related Questions