There are a bunch of examples for drag and drop Kendo grids floating around the web, but this is the only reordering solution that has worked for me with an in-cell editable grid. It features an automatically updating priority queue column with the row index number.
First let’s look at the main reordering functionality, and then complete the user experience with some extra bits for updating the queue.
Setting up drag n drop on the grid is accomplished above using kendoSortable. Beyond that, Kendo leaves reordering the associated grid data up to the user from what I could gather. My solution removes and inserts the row in its new location, and then removes the subsequent delete request from the grid’s private _destroyed array to avoid false deletes. I then update the PriorityOrder column for all rows, as this is the queue that is shown to the user.
Next we need to take care of updating the priority queue when the user inserts a new row. The grid’s Edit event is triggered by Kendo when the add button is clicked, giving focus to the first cell and opening it for editing.
Don’t forget about the user removing a row…
Now let’s take a look at a (simplified) grid definition in Razor code, as I’m using ASP MVC wrappers to generate the grid. If you’re not using wrappers you should be able to make out the important bits.
I have Font Awesome displaying the classic Windows “move” arrow icon as a drag handle in the PriorityOrder queue column as a client template.
When a grid row is inserted, the grid_editcell event is triggered, which causes the queue to refresh. I found that it was necessary to keep the PriorityOrder column editable, so the values could be visually refreshed. To prevent the user from manually changing the queue, any cell in the PriorityOrder column is closed immediately upon click.
Lastly each row has a custom delete button, which triggers the queue refresh when the row is removed.