【问题标题】:Dojo - Rows disappears from DataGrid after calling sortDojo - 调用排序后行从 DataGrid 中消失
【发布时间】:2018-06-12 13:44:51
【问题描述】:

我在对网格进行排序时遇到了 DataGrid 的问题。

由于这个问题,当我们在一个调用流中执行这一系列操作时,所有行都会消失:

  1. 将一项项目添加到网格的存储中。
  2. 从网格的存储中删除一项
  3. 保存商店
  4. 调用 grid.sort。

在调用 grid.sort 后,grid diapers 中的所有行(尽管它们仍在商店中)。如果我们重复相同的程序,它们就会回来。

我有一个复制代码,我的基于 DataGrid 的自定义 Grid 组件在这里: MyGrid.js

如果您像我在Scenarios.js 的第 38 行中所做的那样调用 MyGrid 的 addOneDelOne,您将能够重现该问题。

在此代码中,如果商品超过 4 件,则会从商店中移除商品。

如果添加项目的数量大于删除的项目,如果我们对网格进行排序,问题也不会出现。

我已经在 Dojo 1.9 和 1.13 上测试过了

【问题讨论】:

    标签: javascript datagrid dojo store dojox.grid.datagrid


    【解决方案1】:

    我相信我们找到了解决这个问题的方法。 问题出在 Dojo 的 DataGrid 的 _onFetchBegin 方法上。

    当我们在 DataGrid 上调用 sort 时,它实际上会通过调用 updateRowCount(0) 来清除一些计数器。

    其中一个被清除的计数器是 this.invalidated.rowCount,DataGrid 和 dojo 实际使用它来打印记录。打印的记录数等于 this.invalidated.rowCount 值。

    稍后,在 grid.sort() 调用处理期间,dojo 转到 _fetch(0, isRender); 方法。此方法最终调用 this.store.fetch({...}) ,它根据从商店返回的项目更新网格。它由回调方法_onFetchBegin 和_onFetchComplete 完成。问题出在 _onFetchBegin

    在我们的例子中,从商店返回的项目数等于网格中的行数。 if(this.rowCount != size) 这是错误的。请注意,我们在这里不使用 this.invalidated.rowCount,而是使用 this.rowCount。 this.invalidated.rowCount 之前在 updateRowCount(0) 中设置为 0。通常,当这个条件为真时,我们会调用 this.updateRowCount(size);其中 size 是商店中的商品数量。 dojo 会打印带有行的网格。但在我们的例子中,this.rowCountsize 是相同的(我们添加记录并删除一条记录),因此我们在 DataGrid 中进一步添加了几行

    if(!size){
            this.views.render();
            this._resize();
            this.showMessage(this.noDataMessage);
            this.focus.initFocusView();
        }else{
            this.showMessage();   <- we ended up here. And we we do not update the RowCount :(
        }
    

    如果我们通过在 this.showMessage();

    之前添加 this.updateRowCount(size); 来修改 Dojo 的 DataGrid

    喜欢这个

    else{
            this.updateRowCount(size);
            this.showMessage();
        }
    

    会好的。

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2012-08-03
      • 2013-03-08
      • 2010-12-01
      • 2013-11-03
      • 2011-07-29
      • 1970-01-01
      • 2014-11-01
      • 2011-01-08
      相关资源
      最近更新 更多