I have a grid that uses inline editing. There are also many pages of data, and I noticed that if I sort by any column, then click the "Add new record" button, I don't see the new row appear (I assume it is created at the end of the last page). However when I go to the last page, the row is already created, except it is all blank! I have some required fields that the user needs to fill in before creating the row, but in this situation, the row is created by itself without any values. This blank row only appears on the frontend (doesn't do anything serverside), and clicking "Update" then "Cancel" removes the row from the table...
Preferably, I would like to be able to jump to the page that contains the created row so that the user doesn't have to go looking for a blank row if they try inserting while the grid is sorted.
Thanks
10 Answers, 1 is accepted
http://dojo.telerik.com/Aveze
Here is a sample replicating the issue, if you sort the first column in descending order (click the column header twice) and try to add a row, it will be on the last page. When you go to the last page, the row is already "created" (not in edit mode)
Hello Andy,
I am afraid that this is expected behavior which is due to the way the new records' creation is handled. The "Add new record" in the KendoUI Grid inserts the new item before the first record from the current page position in the original (without sort, page, filtering etc. applied) data. When sorting is applied this new item's position may not match the current page - thus it may be not visible.
Regarding the required fields - it is only UI validation and when the item is not on opened for edit the validation will not be triggered.
I am afraid currently I can not suggest any suitable workaround to handle the right position of the newly inserted item.
Regards,
Boyan Dimitrov
Telerik
// clear filters/sort if the user wants to add a row
$(document).on(
"mouseup"
,
'a.k-button.k-button-icontext.k-grid-add'
,
function
() {
$(
"form.k-filter-menu button[type='reset']"
).trigger(
'click'
);
$(
"#gridName"
).data(
"kendoGrid"
).dataSource.sort({});
});
Found a decent workaround, this removes all sorting and filters from the grid when you release the mouse button on "Add new record", and then you will be able to see the new row.
I think this behaviour is illogical and not user friendly. The workaround is OK, but I don't think users should have to have their sorting reset when adding a new record.
Why shouldn't it be on the top row, where you'd expect it?
If someone creates a new entry, who would expect to navigate to another page before they can set the attributes?!! By that time, the row is no longer editable and fields say 'not defined'.
Definitely not professional.
Thank you for the feedback.
I will forward this to the developers' team to check if we can make changes to the Grid Add new records behavior in order to take the current sorting criteria into account.
Regards,
Stefan
Progress Telerik
Currently, the behavior is not changed as changing it will cause a breaking change in the widget.
I can agree that this may be strange behavior, but it is required in the current implementation.
I can suggest submitting a feature request and based on the community feedback we may implement it in a future release:
http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback?category_id=170280
Regards,
Stefan
Progress Telerik
$(".k-grid-add").on("click", function (e) {
var grid = $("#gridClienti").data("kendoGrid");
grid.dataSource.sort({});
//var dataSource = grid.dataSource;
//var pageNumber = dataSource.data().length;
//dataSource.insert(pageNumber, {});
//dataSource.page(dataSource.totalPages());
//grid.editRow(grid.tbody.children().first());
});[quote]Stefan said:Hello, David,
Currently, the behavior is not changed as changing it will cause a breaking change in the widget.
I can agree that this may be strange behavior, but it is required in the current implementation.
I can suggest submitting a feature request and based on the community feedback we may implement it in a future release:
http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback?category_id=170280
Regards,
Stefan
Progress Telerik
[/quote] This my solution
Hi Alessandro,
Thank you for sharing your approach with the community, I am sure someone would find it useful. This workaround will indeed also remove the sorting of the Grid and the newly created item will appear on the top row.
Regards,
Aleksandar
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.