簡體   English   中英

如何防止Kendo Sortable / Integration-ListView中的項目進行排序(修復位置)?

[英]How to prevent an item to be sorted (fix positon) in Kendo Sortable / Integration - ListView?

var dataSource = new kendo.data.DataSource({
        data: anArray
    })

var listView = $("#listView").kendoListView({
    name: "listView",
    tagname: "div",
    dataSource: dataSource,
    template: kendo.template($("#listview-template").html()),
});

listView.kendoSortable({
        filter: ">div.myclass",
        cursor: "move",
        placeholder: function (element) {
            return element.clone().addClass("placeholder").text("position here")
        },
        hint: function (element) {
            return element.clone().removeClass("k-state-selected");
        },
        change or move or end?: function(e){
            if(e.newIndex==35){
                 --e.newIndex;
                 console.log(e.newIndex); //output is 34, but the element is moved to 35
            }
        }
});

我想防止被拖動的項目可以在itemA之后插入(相反,可以將其插入到先前的索引中),並且不能阻止itemA。

因此itemA必須保持位置固定。

我找到了答案,這是一個演示: https : //demos.telerik.com/kendo-ui/sortable/filter-disable

對於我的特定情況:無需修改e.newIndex。

使用filter: "div.myclass.sortable" ,我只允許對分類為“ sortable”的div進行排序。 我為所有div.myclass元素賦予可排序的類(在我的Kendo-listview-template中)。

為了防止div排序,我對其進行搜索並刪除可排序的類:

var sortableItems = $(".sortable");
var nonSortableItem = sortableItems[35];               

nonSortableItem.classList.remove("sortable"); //now that one stays fix 

如果只希望不能移動某個項目(但在移動其他項目時不必保持固定),則必須使用disable而不是filter(也請參見上面的演示中的@)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM