[英]kendo grid datasource not update, when push new data
我有一個可以選擇買家的數組對象,如果選擇我會將他們的數據推送到selectedBuyers
,如果取消選擇將從selectedBuyers
過濾掉。 所以我想在推送/過濾數組時更新劍道網格。
我測試的是當我將新對象推送到數組時,我調用$("#my-grid").data("kendoGrid").dataSource.read();
網格有更新,這個工作正常。 然而,當我從數組中過濾掉一些對象,並調用$("#my-grid").data("kendoGrid").dataSource.read();
或$("#my-grid").data("kendoGrid").refresh();
或兩者兼而有之,網格仍顯示舊數據。
var selectedBuyers = [{
"Name":"A",
"Price":"",
"Total":""
},{
"Name":"B",
"Price":"",
"Total":""
}];
$("#my-grid").kendoGrid({
dataSource: {
data: selectedBuyers,
schema: {
model: {
fields: {
Name: { type: "string" },
Price: { type: "string" },
Total: { type: "string" },
}
}
},
pageSize: 5,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
pageSizes: [5, 10, 15, 20],
},
scrollable: true,
dataBound: onbuyerDataBound,
columns: [ {
field: "Name",
title: "Name",
width: 100
},
{
field: "Price",
title: "Price",
width: 100
},
{
field: "Total",
title: "Total",
width: 110,
}]
});
你不能只是過濾掉你不想要的數據。 您需要remove
其從dataSource
remove
。
var dataSource = new kendo.data.DataSource({
data: [
{ id: 1, name: "Jane Doe" },
{ id: 2, name: "John Doe" }
],
schema: {
model: { id: "id" }
}
});
$("#grid").kendoGrid({
dataSource: dataSource
})
$("#remove").kendoButton({
click: function() {
var dataItem = dataSource.at(0);
dataSource.remove(dataItem);
}
});
工作示例:刪除網格項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.