我为这样的网格实现了拖放:
var mainGrid = $("#grid").kendoGrid({
dataSource: mainDataSource,
columns: ["id", "name", "phone"],
scrollable: true,
editable: true,
navigatable: true,
height: 200
}).data("kendoGrid");
mainGrid.table.kendoDropTarget({
group: "gridGroup",
drop: function (e) {
var draggedRows = e.draggable.hint.find("tr");
e.draggable.hint.hide();
var dropLocation = $(document.elementFromPoint(e.clientX, e.clientY)),
dropGridRecord = mainDataSource.getByUid(dropLocation.parent().attr("data-uid"))
if (dropLocation.is("th")) {
return;
}
var beginningRangePosition = mainDataSource.indexOf(dropGridRecord), //beginning of the range of dropped row(s)
rangeLimit = mainDataSource.indexOf(mainDataSource.getByUid(draggedRows.first().attr("data-uid"))); //start of the range of where the rows were dragged from
//if dragging up, get the end of the range instead of the start
if (rangeLimit > beginningRangePosition) {
draggedRows.reverse(); //reverse the records so that as they are being placed, they come out in the correct order
}
//assign new spot in the main grid to each dragged row
draggedRows.each(function () {
var thisUid = $(this).attr("data-uid"),
itemToMove = mainDataSource.getByUid(thisUid);
mainDataSource.remove(itemToMove);
mainDataSource.insert(beginningRangePosition, itemToMove);
});
//set the main grid moved rows to be dirty
draggedRows.each(function () {
var thisUid = $(this).attr("data-uid");
mainDataSource.getByUid(thisUid).set("dirty", true);
});
//remark things as visibly dirty
var dirtyItems = $.grep(mainDataSource.view(), function (e) {
return e.dirty === true;
});
for (var a = 0; a < dirtyItems.length; a++) {
var thisItem = dirtyItems[a];
mainGrid.tbody.find("tr[data-uid='" + thisItem.get("uid") + "']").find("td:eq(0)").addClass("k-dirty-cell");
mainGrid.tbody.find("tr[data-uid='" + thisItem.get("uid") + "']").find("td:eq(0)").prepend('<span class="k-dirty"></span>')
};
}
});
JS小提琴:jsfiddle.net/yagamilight1987/R2EyW/
向下滚动到最后一条记录。将最后一条记录拖放到上一个位置。下降有效,但它滚动到网格的顶部。