道场网格:更新后松散选择

Dojo grid : loose selection after update

本文关键字:选择 更新 网格      更新时间:2023-09-26

我目前正在使用Dojo EnhancedGrid,具有分页,过滤和单元格版本。

问题是在一个页面中,我需要在编辑单元格时更新另一个值。当我更新此值时,我会丢失选定的单元格,因此我需要单击下一个单元格以选择它并对其进行修改。因此无法进行输入/编辑/输入/向下/输入/编辑(类似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();

你看到任何解决方案来处理这个问题吗?

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

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

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

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

           $.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);
                            }
                        }
            });

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