Find the index of the currently selected Grid row. Then, you could use the dataSource insert method.
functiontoolbar_click(e) {
var index = $('tr.k-selected').index();
var grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
var newItem = dataSource.insert(index, {});
var newRow = grid.items().filter("[data-uid='" + newItem.uid + "']");
grid.editRow(newRow);
}
In the Dojo linked here the approach from above is demonstrated.
The reason I did not sent the article, but only the snippets is that currently there is an issue in the KB. the following line should be updated to use the class according to the new rendering introduced in 2022 R1
functiontoolbar_click(e) {
var index = $('tr.k-state-selected').index();//index of the selected rowvar grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
var newItem = dataSource.insert(index, {});
var newRow = grid.items().filter("[data-uid='" + newItem.uid + "']");
grid.editRow(newRow);
}
The article will be updated and the used class will be 'k-selected'.
Sorry about that. I was looking for inserting at a specific position and not add (because I thought that adding will provide me with the default functionality of the add button).
Thank you for the link to the knowledge base article.
Neli
Telerik team
commented on 23 May 2023, 05:52 AM
Hi Dan,
I am glad to hear that the provided article and the suggestion were helpful. In case you have additional questions please let us know.