如何防止kendo网格重装?

时间:2016-12-01 16:16:28

标签: javascript angularjs kendo-ui grid

我有两个kendo网格(A,B)... B通过单击A加载它的数据源,它由A中所选行的属性加载。

A.accounts

dataSource: {
    data: this.gridA.dataItem(this.gridA.select()),
},

我的问题是它在BI中必须使用网格更改属性,但是当属性更改网格时它重新加载,如果我在网格中更改属性时有1000行(anyrow,999 ie),滚动回到开头 ...我已阅读并尝试理解它,但无法修复它...根据官方文档,选择的行

var row = this.gridApprovals.select();
var caBean = this.gridApprovals.dataItem(row);

它是一个ObservableObject,因此,当我尝试更改属性时,某些方法(ObservableOject)正在进行此行为,并且网格重新加载,它迭代每个数据源项......

EDITED: 我忘了提及..重要的是保持B网格的变化与其在A选择中的关系之间的关系。 这是一个Dojo项目http://dojo.telerik.com/uYemI/2

1 个答案:

答案 0 :(得分:0)

这个怎么样?

http://dojo.telerik.com/@Stephen/aNije

我删除了k-rebind属性,而是在setCarsGrid()方法中连接dataSource:

$scope.setCarsGrid = function() {
            var row = this.brandGrid.select();
            var brand = this.brandGrid.dataItem(row);
                            var brandObj=brand.toJSON();

            var dataSource = new kendo.data.DataSource({
              data: brand.cars,
              schema:{
                model:{
                  fields:{
                    id:{editable:false},
                    model:{editable:false},
                    color:{type:"string"}
                  }
                },
                parse: function(response) {
                  $.each(response, function(idx, elem) {
                    elem.id = elem.id+10;
                    //if you put a break point here, every time you try to edit 'color' field.. will be stop because datasourse is iterated again 
                    console.log("Grid has been reloaded and the editable field 'color' can be edited :'( the id property has been added +10")
                  });

                  return response;
                }                                    
              }
            });

          // This first time this is called, the carsGrid has not been initialized, so it doesn't exist.
          // But subsequent times, we just need to set the new datasource.
          if (this.carsGrid) {
            this.carsGrid.setDataSource(dataSource);
          }

            $scope.carsGridOptions = {
                    dataSource: dataSource,
                    selectable:true,
                    editable: true,
                    columns: [{
                        field: "id",
                        },{
                        field: "model",
                        },{
                        field: "color",
                    }]
                };                     

        }

基本上,我只是将GRID的初始化与网格的DATASOURCE的设置分开。 第一次,您设置了网格选项并设置了dataSource,然后通过后续时间,我们只需将网格设置为新的dataSource。

这避免了k-rebind行为......我相信这是记录在案的:http://docs.telerik.com/kendo-ui/AngularJS/introduction#widget-update-upon-option-changes

  

这种方法不适用于dataBound小部件,因为这些小部件在每次更改数据时都会重新创建 - 例如,在分页之后。

注意,我真的不知道角度,所以可能有更好的方法来组织这段代码,但它确实有效。