oria / gridx

Just another powerful Dojo grid
Other
162 stars 78 forks source link

Edit.js onApply add old cache-item to error-object in case of server-store-failure #29

Open hvierendeels opened 11 years ago

hvierendeels commented 11 years ago

I am a newbie to gridx. So all what i am telling here may not be true!

When a column has been edited , the new value is written back to the server store via a store.put command.

Then as a result of aspect'ing the store-put-function, the value is updated in grid-cache and displayed . This happens even if the store.put function fails. In that case i would like to restore the old value.

Would it be possible in Edit.js to save the old value and pass it on via the error-object in case of failure?

E.g.

Edit.js

apply: function(rowId, colId){ .... if(cell){ /tshvr4 begin/ var cache_item=lang.clone( g.model._cache._cache[rowId]); /tshvr4 end/ var widget = g.cellWidget.getCellWidget(rowId, colId), .... finish = function(success, e){ if(!success){ console.warn('Can not apply change! Error message: ', e); e['cache_item_old']=cache_item;//tshvr4+ } .... } }

in application one could do then: this.myGrid.connect(this.myGrid.edit,'onApply',function(cell,success,e) { console.log(myModuleName+' onApply success='+success+' cell=',cell); if(e) { console.dir(e); alert(e.response.data); console.log(myModuleName+' cache_item_old=',e.cache_item_old); var cache=cell.grid.model._cache._cache; var id=cell.row.id cache[id]=e.cache_item_old; cell.grid.body.refreshCell(cell.row.visualIndex(),cell.column.index()); } });

Thanks! Fine written framework!

zhuxw commented 11 years ago

Yes this IS a feature that I'm considering adding to gridx. Actually I'm thinking of going further: to add undo/redo to Edit module. Will take your suggestion into consideration. Thanks.

hvierendeels commented 11 years ago

What do you think of the way taken by https://github.com/SitePen/dgrid/

changes are saved in intermediary dirty-object {} keyed by id

zhuxw commented 11 years ago

Yes, this is an approach I'll take into consideration. Thanks for the advice.