Frage

I have am currently using Dojo EnhancedGrid with Pagination, filtering and cell edition.

The problem is that in one page, I need to update another value when a cell is edited. When I update this value, I loose the cell selected so I need to click on the next cell to select it and modify it. It is so not possible to do Enter / edit / enter / down / enter / edit (Excel like edition).

Here is a part of my code :

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();

Do you see any solution to handle this ?

War es hilfreich?

Lösung 2

After many research, I have found the following solution :

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

The timer is needed because there is a short delay before grid update the thus loosing the focus.

Andere Tipps

I too use an enhanced dojo grid, where I had a similar problem. I used this to reload the data right:

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

With this you always should get the last row you manipulated, and eventually also the last selected one... .

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top