PDA

View Full Version : how to move items up and down in grid



Anthony.Hall
10 Feb 2012, 4:33 AM
I wish move items up and down in the grid. I have the following code. The problem i have is that when the record is initially remove i then try to re-add the record but "record is undefined". The key 2 lines are

store.remove(record);
store.insert(index, record);


All of the code.

function moveSelectedRow(direction) { var grid = Ext.getCmp('processGrid');
var record = grid.getSelectionModel().getSelection()[0];
if (!record) {
console.log("no record ");
return;
}
var store = grid.getStore();
var totalCount = grid.getStore().getCount();
var index = grid.getStore().indexOf(record);

console.log(index);
if (direction < 0) {

console.log("down");
index--;
if (index < 0) {
return;
}
} else {
index++;
if (index >= grid.getStore().getCount()) {
return;
}
}


store.remove(record);
store.insert(index, record);
//grid.getSelectionModel().selectRow(index, true);

}

mitchellsimoens
10 Feb 2012, 4:54 AM
Just did a test with the array grid and this works no problem:


var store = grid.getStore(),
record = store.getAt(rowIndex);

store.remove(record);
store.insert(5, record);

Anthony.Hall
10 Feb 2012, 6:45 AM
hmm, very strange. I've tried your code and getting very different results.

function moveSelectedRow(direction) {
var grid = Ext.getCmp('processGrid');


var rowIndex = 1;
var store = grid.getStore(),
record = store.getAt(rowIndex);
console.info(record); // record is defined
store.remove(record);
console.info(record); // record is not defined
store.insert(2, record);




return;
}