【问题标题】:Dojo grid : loose selection after updateDojo 网格:更新后的松散选择
【发布时间】:2013-01-30 11:37:07
【问题描述】:

我目前正在使用带有分页、过滤和单元格编辑的 Dojo EnhancedGrid。

问题是在一个页面中,我需要在编辑单元格时更新另一个值。当我更新这个值时,我失去了选择的单元格,所以我需要单击下一个单元格来选择它并修改它。 无法执行 Enter / edit / enter / down / enter / edit(类似 Excel 的版本)。

这是我的代码的一部分:

var store = new dojo.data.ItemFileWriteStore({'data':data});
var grid = new dojox.grid.EnhancedGrid({
    id: 'grid',
    store: store,
    structure: structure,
    columnReordering: true,
    autoHeight: true,
    autoWidth: true,
    initialWidth: '100%',
    escapeHTMLInData: false,
    plugins: {
            pagination: {
                pageSizes: ["10", "25", "50", "All"],
                description: true,
                sizeSwitch: true,
                pageStepper: true,
                gotoButton: true,
                maxPageStep: 4,
                position: "bottom"

            },
            filter : {}
    },
    onStartEdit: function(inCell, inRowIndex)
    {
        item = grid.selection.getSelected()[0];
        currentVal = item[inCell['field']][0];
    },
    doApplyCellEdit: function(inValue, inRowIndex, inAttrName) {
          if(inValue != currentVal){
               [...]
               $.ajax(url, data, {
                           success:function(data, textStatus) {
                                val = parseInt(data["info"]);
                                if(!isNaN(val)) {
                                    grid.store.setValue(item, 'info', val);
                                    grid.update();
                                } else {
                                    grid.store.setValue(item, 'info', 0);
                                    grid.update();
                                }
                            }
                });
            }

        }


    });
    dojo.byId("gridDiv").appendChild(grid.domNode);
    grid.startup();

你有什么解决办法来解决这个问题吗?

【问题讨论】:

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


    【解决方案1】:

    我也使用了增强的 dojo 网格,在那里我遇到了类似的问题。我用这个来重新加载数据吧:

    require(["dijit/registry"],function(registry)   {
                var grid = registry.byId('grid');
                grid._lastScrollTop=grid.scrollTop;
                grid._refresh();
            });
    

    有了这个,你总是应该得到你操作的最后一行,最后也是最后选择的一行...。

    【讨论】:

    • 它不适用于我的代码。查看我在另一篇文章中找到的解决方案。
    【解决方案2】:

    经过大量研究,我找到了以下解决方案:

               $.ajax(url, data, {
                           success:function(data, textStatus) {
                                val = parseInt(data["info"]);
                                if(!isNaN(val)) {
                                    grid.store.setValue(item, 'info', val);
                                    grid.update();
                                    window.setTimeout(function() {
                                        grid.focus.next();
                                    }, 10);
                                } else {
                                    grid.store.setValue(item, 'info', 0);
                                    grid.update();
                                    window.setTimeout(function() {
                                        grid.focus.next();
                                    }, 10);
                                }
                            }
                });
    

    需要计时器,因为在网格更新之前有一个短暂的延迟,从而失去了焦点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 2011-06-07
      • 2012-06-01
      • 2012-05-23
      • 2013-01-27
      • 2012-05-30
      相关资源
      最近更新 更多