简体   繁体   English

Kendo UI-AngularJS:如何将网格绑定到$ scope上的对象?

[英]Kendo UI - AngularJS: How to bind a grid to an object on $scope?

I am trying to bind a Kendo UI Grid to an object on $scope instead of to kendo.data.dataSource . 我正在尝试将Kendo UI Grid绑定到$scope上的对象,而不是kendo.data.dataSource The grid shows the data (which is in the object) but if I change the data or add new row, the changes are not reflected in the $scope object. 网格显示数据(位于对象中),但是如果更改数据或添加新行,则更改不会反映在$scope对象中。 Why is that? 这是为什么?

My real problem is, I want to show two grids top & bottom and when the user selects a row from top grid, the bottom grid should be populated with the details. 我真正的问题是,我想在顶部和底部显示两个网格,并且当用户从顶部网格中选择一行时,底部网格应填充详细信息。 However, these details are already fetched and kept in the DataSource of the top grid (hence no transport section for bottom grid) because I want to be able to save any changes in batches. 但是,这些详细信息已经获取并保存在顶部网格的DataSource中(因此底部网格没有传输部分),因为我希望能够批量保存任何更改。

This is how I am binding my grids 这就是我绑定网格的方式

Top Grid 顶格

<div kendo-grid="mainGrid"
         k-sortable="true"
         k-editable="true"
         k-selectable="'row'"
         k-filterable="true"
         k-resizable="true"
         k-scrollable='{ "virtual":true }'
         k-on-change="selected = dataItem" 
         k-options="mainGridOptions"
         k-height="165">
    </div>

Bottom Grid 底格

<div kendo-grid="detailGrid"
    k-editable="true"
    k-selectable="'row'"
    k-options="detailGridOptions"
    k-data-source="selected.Details"
    k-height="125"></div>

This is how I add record to bottom grid 这就是我将记录添加到底部网格的方式

$scope.detailGrid.dataSource.add();

So far, I didn't get how to bind Kendo UI grid to an object on $scope. 到目前为止,我还没有如何将Kendo UI网格绑定到$ scope上的对象。 However, for my real problem, I have found a work around. 但是,对于我真正的问题,我找到了解决方法。

I bound on-save event of the child grid, and explicitly marked the current row as dirty. 我绑定了子网格on-save事件,并明确地将当前行标记为脏。

$scope.onDetailGridSave = function () {
   $scope.selected.dirty = true;
};

and in HTML 和HTML

k-on-save="onDetailGridSave()"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM