This example demonstrates how to move ASPxGridView rows using buttons or jQuery Drag&Drop.
To keep the order of rows, it is necessary to set up an extra column to store row order indexes. Then, sort ASPxGridView by this column and deny sorting by other columns. This example stores this information in the unbound column and additionally puts a dictionary "row key = row index" to the session. We have implemented this approach only for demo purposes. You can store this information in your DataSource.
See also:
E1810: How to use jQuery to drag and drop items from one ASPxGridView to another
E3850: How to reorder ASPxTreeList sibling nodes, using buttons or drag-and-drop
E4299: How to move up or down a line a row of ASPxGridView by using external buttons
Question Comments
Added By: Hiren Joshi (Venture) at: 8/20/2013 3:03:21 PM
Hello,
I have seen your example however I have a question from user view point. Once you start to drag a row button you don't have any way to tell which row you are dragging. So unless you remember the row to started with it will be diffcult for users to use this practically. Do you have a way to drag the entire row or have a button with some text to identify the row you are dragging? Please let me know if this is possible.
Added By: Jacob Blumberg at: 8/27/2013 4:05:00 PMI agree, that is what I am looking for too.
Added By: Hiren Joshi (Venture) at: 9/11/2013 10:54:22 AMI was able to use the link tag <a href=""><%#Eval("YourData")%></a> instead of the image; in order to over come the problem of knowing which row is being dragged. So now when I drag the row I can see the text that I am dragging.
Added By: Wouter Stichelbout at: 2/11/2014 7:54:23 AMI there an MVC equivalent?
Added By: Vasily (DevExpress Support) at: 2/11/2014 9:48:17 AMHi Wouter,
I have extracted your question to a separate ticket created on your behalf: Q466606: GridView - How to reorder GridView rows using buttons or drag-and-drop.
Your time and cooperation are appreciated.
Hello,
This approach much more resembles the way Telerik has implemented row dragging and dropping:
function InitalizejQuery() {
var openhand = "url(https://mail.google.com/mail/images/2/openhand.cur), move";
var closedhand = "url(https://mail.google.com/mail/images/2/closedhand.cur), move";
$('.dxgvDataRow, .dxgvFocusedRow').each(function () {
$(this).css({ "cursor": openhand });
});
$('.dxgvDataRow, .dxgvFocusedRow').draggable({
helper: function () {
var result = $("<table class='dxgvTable' cellspacing='0' cellpadding='0' style='opacity:0.7;background-color:#dddddd;'>").append($(this).clone()).append($("</table>"));
$("td", this).each(function (index) {
$("td", result).eq(index).css({ 'width': $(this).width() });
});
return result;
},
axis: "y",
start: function (event, ui) {
$("tr", $(this).parent()).each(function (index) {
$(this).css({ "cursor": closedhand });
$(this).removeClass('dxgvFocusedRow'); // this is the same as removing the focussedrowindex
$(this).addClass('dxgvDataRow');
});
$(this).addClass('dxgvFocusedRow');
},
stop: function (event, ui) {
$(this).css({ "cursor": openhand });
}
});
$('.dxgvDataRow, .dxgvFocusedRow').droppable({
drop: function (event, ui) {
var draggingRowKey = ui.draggable.find("input[type='hidden']").val();
var targetRowKey = $(this).find("input[type='hidden']").val();
gridView.PerformCallback("DRAGROW|" + draggingRowKey + '|' + targetRowKey);
}
, over: function (event, ui) {
var targetRowKey = $(this).find("input[type='hidden']").val();
var rowindex = gridView.keys.indexOf(targetRowKey);
window.setTimeout(function () { gridView.MakeRowVisibleNew(rowindex); }, 100);
$(this).addClass('borderClass');
}
, out: function (event, ui) {
$(this).removeClass('borderClass');
}
});
}
Best Regards,
Ernstjan Freriks