簡體   English   中英

推送新數據時,劍道網格數據源不更新

[英]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.

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