Updating the grid using Enter and Down Arrow Keys

14 replies. Last post: November 1, 2012 6:31 AM by Hans Kristian
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Ahmed DajaniMember

I'd like to be able to cause the grid to update after I edit a cell by hitting the enter or down arrow key.
Hitting either of those keys should update the grid, move down one cell and place it in Edit Mode ready for editing. Much like Excel.

What happens now is if I hit the down arrow key, the grid updates but does not move focus to the below cell. The enter key behaves differently in IE and Firefox. In IE, the grid updates just fine. However, in Firefox, the whole page refreshes and the change is not applied.

The update works if I tab off or move or move to the left/right cell.

My code is below. I'm binding the grid to an Object Data Source.

<ISWebGrid:WebGrid ID="WebGrid1" runat="server" Width="100%" Height="100%" UseDefaultStyle="true" EnableWebResources="Always"
                           DataSourceID="odsAccountLineList" CustomSchemaRetrieval="UseWebGrid">
            <RootTable GridLineStyle="NotSet" DataKeyField="account_line_id" RowHeaders="Yes">
            </RootTable>
            <LayoutSettings DisplayDetailsOnUnhandledError="true"           
                            InProgressUIBehavior="ChangeCursorToHourGlass" StatusBarVisible="true"
                            NewRowLostFocusAction="AlwaysUpdate"
			    RowLostFocusAction="AlwaysUpdate" 
                            AllowColumnMove="Yes"
			    AllowFilter="No" 
                            AllowGrouping="No" 
                            AllowSelectColumns="Yes" 
                            AllowSorting="No"
			    GroupByBoxVisible="false" 
                            AutoHeight="false" 
                            AutoWidth="false" 
                            PagingMode="None"
                            AllowEdit="Yes" 
                            AllowDelete="Yes"
                            AllowMultipleSelection="Yes"
                            UseRelativePositioning="true"
                            CellClickAction="CellSelect"
                            ApplyChangesKey="Enter">
                <AlternatingRowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="LightGray" Wrap="false" Font-Size="8pt" Font-Names="Arial Monospaced"></AlternatingRowStyle>
                <RowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="White" Font-Size="8pt" Wrap="false" Font-Names="Arial Monospaced"></RowStyle>
                <ClientSideEvents OnRowContextMenu="wb_OnRowContextMenu" OnColumnContextMenu="wb_OnColumnContextMenu"
                    OnEnterEditMode="wb_OnEnterEditMode" OnScroll="wb_OnScroll" OnEditKeyDown="wb_OnEditKeyDown" />
		    </LayoutSettings>
        </ISWebGrid:WebGrid>

Client Side JS. I am not including all the client side events. Nothing out of the ordinary is happening there and they are working just fine:

/**
        * Activates Edit Mode for the specified row and column
        */
        function activateEditMode(grid, rowIndex, columnName) {
            if (rowIndex != 0 && rowIndex < grid.TotalRows) {
                var myRow = grid.RootTable.GetRow(rowIndex);
                myRow.BeginEdit();
                myRow.GetCell(columnName).ActivateEdit();
            }
        }
/**
        * Some manual behavior for navigating the grid
        */
        function wbAARS_OnEditKeyDown(controlId, keyCode) {
            // get the grid
            var grid = ISGetObject(controlId);
            // get current information about row and cell
            var activeEditCell = grid.GetActiveEditCell();
            var columnName = wgGetColNameByCell(activeEditCell.element);
            var curRow = activeEditCell.rowElement;
            var curRowIndex = curRow.rowIndex;
            if (keyCode == 38) { // if up arrow
                grid.ExitEdit(1, 0, 0);  // exit and update the row if dirty
                activateEditMode(grid, curRowIndex - 1, columnName);
            }
// Note(XX): I was testing for the enter key here to apply the same logic as the down arrow key
 // else if (keyCode == 13 || keyCode == 40) { // if down arrow or enter key else if (keyCode == 40) { // if down arrow or enter key grid.ExitEdit(1, 0, 0); // exit and update the row if dirty activateEditMode(grid, curRowIndex + 1, columnName); } return true; }

As I understand it, when I call ExitEdit, it refreshes the grid and waits for an XML response back. So activateEditMode gets called, but when the response is received, the focus is returned back to the original editted cell.

Your help is appreciataed. Thanks.

All times are GMT -5. The time now is 11:43 PM.
Previous Next