PDA

View Full Version : Reordering grid rows



intro
25 Sep 2010, 6:59 AM
Hi, please anyone :)) can someone please paste some code for reordering grid with designer,
I am trying to make dnd reorder, but with no luck with 7,8 hours and Ext.ux.dd examples..

i spend a a day on that function and no luck...


I try to put Ext.ux.dd but then when i try to drag, he drag the grid but no rows..
and ge say "grid is undefined",


Thanks in advance.



grid = this.Novostigrid;
Ext.namespace('Ext.ux.dd');

Ext.ux.dd.GridReorderDropTarget = function(grid, config) {
grid = this.Novostigrid;
var grid = this.Novostigrid;
this.grid=this.Novostigrid;
this.target = new Ext.dd.DropTarget(grid.getEl(), {
ddGroup: grid.ddGroup || 'depGridDD'
,grid: grid
,gridDropTarget: this
,notifyDrop: function(dd, e, data){
// determine the row
var t = Ext.lib.Event.getTarget(e);
var rindex = this.grid.getView().findRowIndex(t);
if (rindex === false) return false;
if (rindex == data.rowIndex) return false;

// fire the before move/copy event
if (this.gridDropTarget.fireEvent(this.copy?'beforerowcopy':'beforerowmove', this.gridDropTarget, data.rowIndex, rindex, data.selections) === false) return false;

// update the store
var ds = this.grid.getStore();
if (!this.copy) {
for(i = 0; i < data.selections.length; i++) {
ds.remove(ds.getById(data.selections[i].id));
}
}
ds.insert(rindex,data.selections);

// re-select the row(s)
var sm = this.grid.getSelectionModel();
if (sm) sm.selectRecords(data.selections);

// fire the after move/copy event
this.gridDropTarget.fireEvent(this.copy?'afterrowcopy':'afterrowmove', this.gridDropTarget, data.rowIndex, rindex, data.selections);

return true;
}
,notifyOver: function(dd, e, data) {
var t = Ext.lib.Event.getTarget(e);
var rindex = this.grid.getView().findRowIndex(t);
if (rindex == data.rowIndex) rindex = false;

return (rindex === false)? this.dropNotAllowed : this.dropAllowed;
}
});
if (config) {
Ext.apply(this.target, config);
if (config.listeners) Ext.apply(this,{listeners: config.listeners});
}

this.addEvents({
"beforerowmove": true
,"afterrowmove": true
,"beforerowcopy": true
,"afterrowcopy": true
});

Ext.ux.dd.GridReorderDropTarget.superclass.constructor.call(this);
};

Ext.extend(Ext.ux.dd.GridReorderDropTarget, Ext.util.Observable, {
getTarget: function() {
return this.target;
}
,getGrid: function() {
return this.target.grid;
}
,getCopy: function() {
return this.target.copy?true:false;
}
,setCopy: function(b) {
this.target.copy = b?true:false;
}
});
sm.on('rowselect', this.gridpregleddnd, this);

var ddrow = new Ext.ux.dd.GridReorderDropTarget(g, {
copy: false
,listeners: {
beforerowmove: function(objThis, oldIndex, newIndex, records) {
// code goes here
// return false to cancel the move
}
,afterrowmove: function(objThis, oldIndex, newIndex, records) {
// code goes here
}
,beforerowcopy: function(objThis, oldIndex, newIndex, records) {
// code goes here
// return false to cancel the copy
}
,afterrowcopy: function(objThis, oldIndex, newIndex, records) {
// code goes here
}
}
});

// if you need scrolling, register the grid view's scroller with the scroll manager
Ext.dd.ScrollManager.register(g.getView().getEditorParent());
}

intro
28 Sep 2010, 2:32 AM
:-/ hi i dodnt make this work, please can some one help.
mabe if you made some grid for example to learn how to make ?

Thanks in advance

jarrednicholls
28 Sep 2010, 5:01 AM
Hey intro,

I will move this thread to the Ext JS help forum so the Ext JS community can take a look at this.

Thanks,
Jarred

intro
28 Sep 2010, 5:26 AM
Thanks thanks, i am little bit crazy of trying to make it work:)