在子网格中添加或编辑记录时,Kendo网格数据源无法更新

时间:2016-05-09 19:04:17

标签: jquery kendo-ui kendo-grid kendo-datasource

如果我尝试在子网格中添加或更新网格记录,则网格正在更新但不是网格数据源。我试图从视图中获取网格数据源,该数据源也没有更新的数据。任何人都可以告诉我以下代码的错误

<div id="Grid"></div>
<script type="text/javascript">
   var data = [{
  "BUCode": 6,
  "BUCodeName": "PrinterPix.com",
  "ClientCode": 1,
  "CreatedByCode": 1,
  "CreatedByName": "Bangalore Team",
  "DisplayCode": null,
  "IsActive": false,
  "ParentProductCode": 115,
  "ParentboProductCode": 115,
  "WorkCenterCode": 20,
  "WorkCenterName": "Print",
  "listRoutingPlanActivity": [{
    "ActivityCode": 12,
    "ActivityDisplayCode": null,
    "ActivityName": "Cut",
    "IsActive": false,
    "MachineHours": 0,
    "MachineSetupHours": 0,
    "StandardMinutes": 0,
    "WorkCenterCode": 20,
    "SequenceNumber": 1,
    "listActivityMaterial": [{
      "ActivityCode": 12,
      "Code": 0,
      "ActivityName": "Cut",
      "BUCode": 6,
      "BUCodeName": "PrinterPix.com",
      "ChildProductCode": 0,
      "ChildboProductCode": null,
      "ClientCode": 1,
      "CreatedByCode": 0,
      "IsActive": false,
      "ParentProductCode": 0,
      "ParentboProductCode": null,
      "ChildCategoryCode": 128,
      "ChildCategoryName": "_Raw Materials_",
      "ParentCategoryCode": 0,
      "ParentCategoryName": "",
      "Quantity": 0,
      "WorkCenterCode": 20
    }],
    "Code": 0,
    "OutputProductCode": 0,
    "OutPutBoProduct": ""
  }]
}, {
  "BUCode": 6,
  "BUCodeName": "PrinterPix.com",
  "ClientCode": 1,
  "CreatedByCode": 1,
  "CreatedByName": "Bangalore Team",
  "DisplayCode": null,
  "IsActive": false,
  "ParentProductCode": 115,
  "ParentboProductCode": 115,
  "WorkCenterCode": 23,
  "WorkCenterName": "Streatch",
  "listRoutingPlanActivity": [{
    "ActivityCode": 15,
    "ActivityDisplayCode": null,
    "ActivityName": "Stretched",
    "IsActive": false,
    "MachineHours": 0,
    "MachineSetupHours": 0,
    "StandardMinutes": 0,
    "WorkCenterCode": 23,
    "SequenceNumber": 2,
    "listActivityMaterial": [{
      "ActivityCode": 15,
      "Code": 0,
      "ActivityName": "Stretched",
      "BUCode": 6,
      "BUCodeName": "PrinterPix.com",
      "ChildProductCode": 0,
      "ChildboProductCode": null,
      "ClientCode": 1,
      "CreatedByCode": 0,
      "IsActive": false,
      "ParentProductCode": 0,
      "ParentboProductCode": null,
      "ChildCategoryCode": 128,
      "ChildCategoryName": "_Raw Materials_",
      "ParentCategoryCode": 0,
      "ParentCategoryName": "",
      "Quantity": 0,
      "WorkCenterCode": 23
    }],
    "Code": 0,
    "OutputProductCode": 0,
    "OutPutBoProduct": ""
  }]
}, {
  "BUCode": 6,
  "BUCodeName": "PrinterPix.com",
  "ClientCode": 1,
  "CreatedByCode": 1,
  "CreatedByName": "Bangalore Team",
  "DisplayCode": null,
  "IsActive": false,
  "ParentProductCode": 115,
  "ParentboProductCode": 115,
  "WorkCenterCode": 34,
  "WorkCenterName": "Sticking",
  "listRoutingPlanActivity": [{
    "ActivityCode": 66,
    "ActivityDisplayCode": null,
    "ActivityName": "Sticking",
    "IsActive": false,
    "MachineHours": 0,
    "MachineSetupHours": 0,
    "StandardMinutes": 0,
    "WorkCenterCode": 34,
    "SequenceNumber": 3,
    "listActivityMaterial": [{
      "ActivityCode": 66,
      "Code": 0,
      "ActivityName": "Sticking",
      "BUCode": 6,
      "BUCodeName": "PrinterPix.com",
      "ChildProductCode": 0,
      "ChildboProductCode": null,
      "ClientCode": 1,
      "CreatedByCode": 0,
      "IsActive": false,
      "ParentProductCode": 0,
      "ParentboProductCode": null,
      "ChildCategoryCode": 128,
      "ChildCategoryName": "_Raw Materials_",
      "ParentCategoryCode": 0,
      "ParentCategoryName": "",
      "Quantity": 0,
      "WorkCenterCode": 34
    }],
    "Code": 0,
    "OutputProductCode": 0,
    "OutPutBoProduct": ""
  }]
}];
var gridDataSource = new kendo.data.DataSource({

  transport: {
    read: function(options) {
      options.success(data);
    }
  },
  schema: {
    model: {
      id: "WorkCenterCode",
      fields: {
        WorkCenterCode: {
          editable: false
        },
        WorkCenterName: {
          editable: false,
        }
      }
    }
  },
});



$("#Grid").kendoGrid({
  autoBind:true,
dataSource: gridDataSource,
sortable: false,
pageable: false,
scrollable: true,
// detailInit: secondGridInit,                  
columns: [{
  field: "WorkCenterName",
  title: "Work Center Name"
}]
})

});


function secondGridInit(e) {

    console.log(JSON.stringify(e.data.listRoutingPlanActivity));
    var findByID = function(id) {
      return e.data.listRoutingPlanActivity.find(function(item) {
        return item.ActivityCode == id;
      });
    };
    $("<div id='activity' class='activity'/>").appendTo(e.detailCell).kendoGrid({
          dataSource: {
            transport: {
              read: function(options) {
                options.success(e.data.listRoutingPlanActivity.toJSON());
              },
              update: function(options) {
                e.data.dirty = true;
                options.success();
              },
            },
            schema: {
              model: {
                id: "ActivityCode",
                fields: {
                  WorkCenterCode: {
                    editable: false
                  },
                  ActivityCode: {
                    editable: false
                  },
                  ActivityName: {
                    editable: false
                  },
                  IsActive: {
                    editable: false,
                    defaultValue: true
                  },
                  StandardMinutes: {
                    type: "number"
                  },
                  MachineSetupHours: {
                    type: "number"
                  },
                  MachineHours: {
                    type: "number"
                  },
                }
              }
            }
          },
          scrollable: true,
          editable: "popup",
          columns: [{
              field: "ActivityName",
              title: "Activity"
            }, {
              field: "StandardMinutes",
              title: "Standard Time"
            }, {
              field: "MachineSetupHours",
              title: "Machine Setup Time"
            }, {
              field: "MachineHours",
              title: "Machine Hours"
            }, {
              command: "edit"
            },

          ]
        }
</script>

2 个答案:

答案 0 :(得分:0)

当你初始化子网格时,它有自己的数据源,从父项1和它的不同对象形成,没有对父数据源的反射。

因此,如果您需要更新数据,只需检索父行的子网格数据并在其中搜索。

答案 1 :(得分:0)

我也有这个问题。当我们更改kendo网格中的某些数据以在UI上显示时,只有html更改而不是dataSource。 因此,我们在网格html中所做的更改也必须在dataSource中同等地进行。 喜欢这个

$("#grid").data("kendoGrid").dataSource.data()[i - 1].fclty_cd = faculty; // dataSource changes
$($($('#grid table tr[role=row]')[i]).find("td")[11]).text(faculty); // html changes