Webgrid screen scroll when use down arrow to exit edit

2 replies. Last post: October 25, 2013 11:27 AM by luwen zhang
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
luwen zhangMember

I use webgrid with layout setting CellClickAction="RowSelect" and clienSideEvent "OnEditKeyDown"

I use down arrow to exit edit and move cursor to the same column next row. The grid has lots of rows and you can see the vertical scroll bar.  Now you edit a column in the first row of grid and press down arrow, the entire row is scrolled up and out of sight. How to make sure we can see the edited row when pressing the down arrow?

Here is the code.

function OnEditKeyDown(controlId) {

    var grid = ISGetObject(controlId);

    var selectedObject = grid.GetSelectedObject();
    var selectedRow = selectedObject.ToRowObject();

    if (selectedRow.Type == "FilterRow") {
        return true;
    }
    else if  (selectedRow.Type != "NewRow" && (event.keyCode == "13" || event.keyCode == "40" || event.keyCode == "38")) {
                window.setTimeout(function () { grid.ExitEdit(1, 0, 0); }, 10);
                var nextRow = selectedRow.GetNextRow();
                if (nextRow != null) {
                    var ac = grid.GetActiveEditCell();
                    var curRow = ac.rowElement;
                    var tblElm = wgGetTable(curRow);
                    var curRowIndex = curRow.rowIndex;
                    var tbl = grid.Tables[ac.tblName];
                    var isParent = (tbl.GetChildTables().length > 0) ? true : false;
                    var i = (isParent) ? 2 : 1;
                    var nextRow =  event.keyCode == "38" ? curRowIndex - i: curRowIndex + i;
                    //check if current row is the last row of the table
                    if (nextRow >=0 && nextRow < tblElm.rows.length ) {
                        //get destination now   
                        var destRow = wgGetRowByPosition(tblElm, nextRow);
                        //highlight the destination row       
                        //get the column name    
                        var cellName = wgGetColNameByCell(ac.element);
                        //get the destination cell    
                        var destCell = wgGetCellByName(destRow, cellName);

                        wgGetRowByElement(destRow).Select();
                        wgHighlightEditCell(destCell);
                    }
                }
                return false;
            }
         else { return true; }
    }
Thanks
All times are GMT -5. The time now is 4:58 AM.
Previous Next