Hi,
I am having problem in moving rows in webgrid either up or down. The error seem to be appear when I try to swap the position of the last 2 rows. The javascript error message is 'Node' is null or not an object. My Javascript code as below. Would be glad if someone can help me on this. Thanks.
function MoveRow(gridName,direction) { var oGrid = igtbl_getGridById(gridName); var selectedRow = oGrid.getActiveRow();
if(direction=="up" && selectedRow.getIndex()>0) { try { var toPosition = selectedRow.getIndex()-1; oGrid.Rows.remove(selectedRow.getIndex()); oGrid.Rows.insert(selectedRow,toPosition); } catch(e) { alert(e.message); return; } } else if(direction=="down" && (selectedRow.getIndex()+1)< oGrid.Rows.length) { try { var toPosition = selectedRow.getIndex()+1; oGrid.Rows.remove(selectedRow.getIndex()); oGrid.Rows.insert(selectedRow,toPosition); } catch(e) { alert(e.message); return; } } return true; }
Thanks for asking the question, helped me!
I had the same problem, and I removed the last row and inserted it one position above when this case happened, like this:
function uwgOptions_ClickCellButtonHandler(gridName, cellId){ var grid=igtbl_getGridById(gridName); var cell = igtbl_getCellById(cellId); if(cell.getValue()=="Down") { if(cell.getRow().getIndex()<grid.Rows.length-1) { try { var index = cell.getRow().getIndex(); if(grid.Rows.length-1<=index+1) { var row = grid.Rows.getRow(index+1); grid.Rows.remove(cell.getRow().getIndex()+1); grid.Rows.insert(row,index); } else { var row = cell.getRow(); grid.Rows.remove(cell.getRow().getIndex()); grid.Rows.insert(row,index+1); } } catch(e) { alert(e.message); return; } } }}
Hope it helps
Johni Ecco
If you step through your logic, I think you'll have a "aha" moment. Removing a row from the grid changes the total row count. That means your index needs to be offset by 1. For example, remove the row before last and insert it after the last row.. the last row's index changes the moment remove the row above it.
Hope this helps,
-Tony