View Full Version : keep single column values during gridrow drag-drop

5 Jun 2008, 4:53 PM
I'm doing a drag-drop on my grid rows, which correctly moves the rows and places them, with all the row values into the newly selected row. The problem I'm facing is that I want to maintain one of the columns so that the values of that column always stay the same despite the row changing. Is there a way to skip the replacement of values for one column.

var ddrow = new Ext.dd.DropTarget(grid, {
ddGroup : 'testDDGroup',
notifyDrop : function(dd, e, data){
var sm=selModel;
var rows=sm.getSelections();
var cindex=dd.getDragData(e).rowIndex;

if (typeof cindex != "undefined") {
for (i = 0; i < rows.length; i++) {
if(!this.copy) {

5 Jun 2008, 5:08 PM
I don't think so. That kinda goes against the way the grid works.
You could always just set it yourself.
It may be an extra bit of code, but i think its the only way.

There may be a more efficient way of doing it, but this type of thing would work...

var saveValues = {};
for(var i=0; i<store.getCount(); i++) {
saveValues[i] = store.getAt(i).get('valueDataIndex');

//complete the move

for(var i=0; i<store.getCount(); i++) {
store.getAt(i).set('valueDataIndex', saveValues[i]);

5 Jun 2008, 6:49 PM
I would think there would be a fair amount of use for this. Such as when someone has a numbered grid with a column that includes row numbers. They drag-drop the grid rows but want to make sure the row numbers stay the same....in my case it is a ranking system.

I guess it wouldn't be that much work to do another for loop or custom update for the column after the drag drop rendering had happened. I just wondered if anyone else had faced this problem and what their solution had been.

5 Jun 2008, 8:31 PM
I found a way that works for me. I don't know if it is the best solution but it might help others. I simply changed the data store value for each position in the column, after I did my drag-drop.

var rowCount = datastore.reader.jsonData.RowsInGrid.length;
var jCount = 0;
for (j=rowCount; j> 0; j--){
var columnRecord = datastore.getAt(jCount);
var newValue = j;
columnRecord.set('columnMappedName', newValue);

5 Jun 2008, 8:32 PM
Oops Para, I see you did something almost the same in your post, I hadn't seen your example code in the post. Thanks for the help and hopefully it helps someone else.