1
votes

I am trying to create a function, that when an arrow link (up or down) is clicked on a certain row, the row will move up or down.

Is there a way to dynamically move rows in the data this way?

(I know there is the RowMoveManager but the requirements request arrow links instead of drag-able)

2
Are you using a DataView with your grid?idbehold
Yes, I am using DataViewsunzyflower

2 Answers

1
votes

I found a way to do it, although it might not be the most efficient way. I have a column in my data, rank and I added an onClick function on an arrow moveOneUp(index);

function moveOneUp(rowIndex) {
        _grid.dataView.getItem(rowIndex).rank = parseInt(_grid.dataView.getItem(rowIndex).rank)-1 ;
        _grid.dataView.getItem(rowIndex-1).rank = parseInt(_grid.dataView.getItem(rowIndex-1).rank)+1;
        _grid.dataView.fastSort('rank');
}

If anyone needs the rest of the arrow functions:

function moveOneDown(rowIndex) {
    _grid.dataView.getItem(rowIndex).rank = parseInt(_grid.dataView.getItem(rowIndex).rank)+1 ;
    _grid.dataView.getItem(rowIndex+1).rank = parseInt(_grid.dataView.getItem(rowIndex+1).rank)-1;
    _grid.dataView.fastSort('rank');
}

function moveTop(rowIndex) {
    _grid.dataView.getItem(rowIndex).rank = 0 ;
    _grid.dataView.fastSort('rank');
}


function moveBottom(rowIndex) {
    _grid.dataView.getItem(rowIndex).rank = parseInt(_grid.dataView.getLength())+1;
    _grid.dataView.fastSort('rank');
}
0
votes
function moveOneUp(rowIndex) {
    dataViewReorder.beginUpdate();
    rowIndex = rowIndex - 1;
    dataViewReorder.getItem(rowIndex).intOrd0 = parseInt(dataViewReorder.getItem(rowIndex).intOrd0) - 1;        
    dataViewReorder.getItem(rowIndex - 1).intOrd0= parseInt(dataViewReorder.getItem(rowIndex - 1).intOrd0) + 1;
    dataViewReorder.fastSort('intOrd0');

    dataViewReorder.setItems(dataReorder);
    dataViewReorder.endUpdate();

    gridReorder.setData(dataViewReorder);
    gridReorder.render();
}
function moveOneDown(rowIndex) {
    dataViewReorder.beginUpdate();
    rowIndex = rowIndex - 1;
    dataViewReorder.getItem(rowIndex).intOrd0= parseInt(dataViewReorder.getItem(rowIndex).intOrd0) + 1;
    dataViewReorder.getItem(rowIndex + 1).intOrd0= parseInt(dataViewReorder.getItem(rowIndex + 1).intOrd0) - 1;
    dataViewReorder.fastSort('intOrd0');

    dataViewReorder.setItems(dataReorder);
    dataViewReorder.endUpdate();

    gridReorder.setData(dataViewReorder);
    gridReorder.render();
}