$("#Grid").ejGrid({ dataSource: data, . . . $("#Grid").on("keydown", function (e) { var obj = $("#Grid").ejGrid("instance"); var index = obj.selectedRowsIndexes[0]; if (e.keyCode == 38 && index != 0) { $(obj.getRows()).eq(index - 1).before(obj.getRowByIndex(index)); //move rows to up
//refresh alternative row var prev = $(obj.getRows()).eq(index - 1).attr("class"); var next = $(obj.getRows()).eq(index).attr("class")
obj.getRowByIndex(index).removeClass('e-row e-alt_row').addClass(prev); obj.getRowByIndex(index - 1).removeClass('e-row e-alt_row').addClass(next); } if (e.keyCode == 40 && (obj.getRows().length - 1 != index)) { $(obj.getRows()).eq(index + 1).after(obj.getRowByIndex(index)); //move rows to down
//refresh alternative row var prev = $(obj.getRows()).eq(index + 1).attr("class"); var next = $(obj.getRows()).eq(index).attr("class")
obj.getRowByIndex(index).removeClass('e-row e-alt_row').addClass(prev); obj.getRowByIndex(index + 1).removeClass('e-row e-alt_row').addClass(next); } |
$("#Grid").on("keydown", function (e) { var obj = $("#Grid").ejGrid("instance"); var index = obj.selectedRowsIndexes[0];
. . . }); |
$("#Grid").on("keydown", function (e) { if (e.keyCode == 38 && index != 0) { $(obj.getRows()).eq(index - 1).before(obj.getRowByIndex(index)); //move rows to up . . . . } if (e.keyCode == 40 && (obj.getRows().length - 1 != index)) { $(obj.getRows()).eq(index + 1).after(obj.getRowByIndex(index)); //move rows to down . . . } |
If your requirement is to replace the row position, at present we have row drag and drop feature in TreeGrid, where you can cut any row and paste it another position as sibling above, below or as a child corresponding to another row. Please refer the below code snippet to enable the row drag and drop in TreeGrid.
<ej:TreeGrid ID="TreeGrid" runat="server" AllowSelection="True" //... AllowDragAndDrop="true"> <DragTooltip ShowTooltip="true" /> //... </ej:treegrid> |
We have also prepared a sample based on this and you can find the sample under the following location.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeGridDragAndDrop1866440379
Regards,
Balaji Marimuthu
Hi Jorge,
We can restrict the row dragging to be handled within the parent node with the help of RowDragStop and RowDragStart Client side event. Please refer the below code example for details.
<ej:TreeGrid ID="Treegrid" runat="server" //… RowDragStop="rowDragStop" RowDragStart="rowDragStart"> </ej:TreeGrid> <script type="text/javascript"> function rowDragStart(args) { dragRow = $.extend({}, args.draggedRow); } function rowDragStop(args) { if (args.targetRow.parentItem != dragRow.parentItem) args.cancel = true; } </script> |
Here we have taken the dragged row in the RowDragStart event and compared that parent item with the dropped Record taken in the RowDragStop event.
We have also prepared a sample based on this and you can find the sample under the following location.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/RowDragging1212042752
Regards,
Mahalakshmi K.
Hi Jorge,
As we said in our previous update, there is no support to move the rows using key up and down. Due to the hierarchy structure in TreeGrid there are some complexity in providing an exact workaround for this requirement. So we have logged a feature report regarding this. A support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Please let us know if you require further assistance on this.
Regards,
Mahalakshmi K.