我有一个无法排序的列表视图。当我拖放项目,并且Ajax调用存储过程来更新显示顺序时,这些项目将恢复为原始顺序。
数据库正在更新,所以我知道它不是数据库问题。没有错误消息,存储过程返回"成功"。也许我有列表视图和可排序设置错误?
var DataSource;
$("#VideoView").kendoListView({
dataSource: {
type: "json",
transport: {
read: {
type: "Get",
contentType: "application/json; charset=utf-8",
url: "../api/Admin_Videos",
dataType: "json"
},
timeout: 120000
},
sort: [{ field: "DisplayOrder", dir: "asc" }],
serverSorting: true
},
dataBound: function () {
$(this.items()).on("dblclick", function () {
data = DataSource[$("div.product").index(this)];
EditVideo(data);
});
},
dataBinding: function() {
DataSource = this.dataSource.data();
},
template: kendo.template($("#VideoViewTemplate").html())
});
$("#VideoView").kendoSortable({
filter: ">div.product",
cursor: "move",
placeholder: function (element) {
return element.clone().css("opacity", 0.1);
},
hint: function (element) {
return element.clone().removeClass("k-state-selected");
},
change: function (e) {
var items = $("#VideoView").data("kendoListView").items();
var itemList = items.children("img");
var newList = '';
for (var i = 0; i < items.length; i++) {
newList = newList + itemList.eq(i).attr("id") + ','
}
newList = newList.substring(0, newList.length - 1);
$.ajax({
type: "Post",
contentType: "application/json; charset=utf-8",
url: "../api/Admin_VideoReorder",
datatype: "json",
data: JSON.stringify({ ID: newList }),
success: function (d) {
// rebind data
$("#VideoView").data("kendoListView").dataSource.read();
}
});
}
});