这是我的视图,其中我有一个与网格集成的 Sortable。这很好用,但问题是 Grid 是分组的。而且,我希望每个组都有自己的可排序功能,这意味着用户不应该能够将行从一个组拖放到另一个组。我怎么做?我是否必须为每个组设置单独的 Sortables?
@(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>