這裏是我的View,其中我有一個可與Grid集成的Sortable。這工作正常,但問題是網格分組。而且,我希望每個組都具有自己的可排序功能,這意味着用戶不應該能夠將行從一個組拖放到另一個組。我怎麼做?我是否必須爲每個組單獨分類?Kendo Sortable與分組網格集成
@(Html.Kendo().Grid<QRMT.ViewModels.SubsystemViewModel>()
.Name("subsystems")
.ToolBar(toolbar => toolbar.Create().Text("Add new Subsystem"))
.Columns(columns =>
{
columns.ForeignKey(c => c.SystemId, new SelectList(ViewBag.Systems, "Value", "Text")).Hidden();
columns.Bound(c => c.SubsystemCode);
columns.Bound(c => c.SubsystemDesc);
columns.Command(c => { c.Edit(); c.Destroy(); }).Width(200);
})
.Editable(e => e.Mode(GridEditMode.PopUp).Window(window => window.Width(500)))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Sync("onSync").Error("onError"))
.Model(model =>
{
model.Id(m => m.SubsystemId);
})
.Group(group => group.Add(m => m.SystemId))
.Create(create => create.Action("Add", "Subsystems"))
.Read(read => read.Action("Read", "Subsystems"))
.Update(update => update.Action("Update", "Subsystems"))
.Destroy(destroy => destroy.Action("Delete", "Subsystems"))
)
.Events(events => events.Edit("onEdit"))
)
@(Html.Kendo().Sortable()
.For("#subsystems")
.Filter("table > tbody > tr:not(.k-grouping-row)")
.Cursor("move")
.HintHandler("noHint")
.PlaceholderHandler("placeholder")
.ContainerSelector("#subsystems tbody")
.Events(events => events.Change("onChange"))
)
<script type="text/javascript">
var noHint = $.noop;
function placeholder(element) {
return element.clone().addClass("k-state-hover").css("opacity", 0.65);
}
function onEdit(e) {
if (e.model.isNew()) {
$('.k-window-title').text("Add");
}
}
function onSync(e) {
this.read();
}
function onError(e) {
alert(e.errors);
}
function onChange(e) {
var grid = $("#subsystems").data("kendoGrid"),
skip = grid.dataSource.skip(),
oldIndex = e.oldIndex + skip,
newIndex = e.newIndex + skip,
data = grid.dataSource.data(),
dataItem = grid.dataSource.getByUid(e.item.data("uid"));
grid.dataSource.remove(dataItem);
grid.dataSource.insert(newIndex, dataItem);
}
</script>
<style>
.k-grid tbody tr:not(.k-grouping-row) {
cursor: move;
}
</style>
好了,感謝您的建議,但有更簡單的解決方法。我只是在每一行上添加上下箭頭以在組內向上和向下移動記錄。我不必使用Kendo Sortable功能。 – ataravati
那麼,你的問題是使用拖放..你接受的答案甚至不正確,如我所示。 – SDM