Hello,
I am having a ultra webgrid (Version=7.2.20072.61) with AllowAddNewDefault="Yes" and the AddNewRowDefault set as visible. This grid is having 7 columns and when the page loads the gris is empty (i.e. it doesn't have any records).
My requirement is that when the users finishes inserting data in 4th column and hits "Enter Key" a new row should get created and focus should shift to the first cell of this new row. This operation should happen on the client-side.
For this I have used the AfterExitEditMode client-side event and when this event is called for the 4th column I am calling the igtbl_addNew(gridName,0) function to added a new row to the grid. But for some reason after calling this function, two new rows get added to the grid one before the current row and one after the current row. I just want the row to be added after the current row. How can I fix this Issue?
Also, I am not sure how I can set the focus on to the first cell of the new row.
Thanks,Rajiv
You can use the KeyDownHandler of ClientSideEvents and use the JS function to add new row and get focus on cell with methods scrollToView and activate. Plase taka e look at the code below:<ClientSideEvents KeyDownHandler="Action" /> <script type="text/javascript"> function Action(gridID, cellID, key) { if (key == 13) { var grid = igtbl_getGridById(gridID); igtbl_addNew(gridID, 0) var getNewCell = "UltraWebGrid1_rc_" + (grid.Rows.length - 1) + "_0"; var cell = igtbl_getCellById(getNewCell); cell.activate(true); cell.scrollToView(true); //to do some manipulation with the cell } return true; } </script>
Hope this helps.
Ivan, Thank you for the reply.
I couldn't get the above code to work for my web page, though the new row got added but the first cell in the new row was not having the focus.
Could you please provide me the working sample of the above code? That will be of great help to me.
Thanks,
Rajiv
Maybe you can use some of the CSOM functions of the grid documented here:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR3.5/html/WebGrid_Object_CSOM.html
From what I see, calling beginEdit on the grid after activating the cell might be what you need:
Puts an active cell into the edit mode. A cell must be activated before the method is invoked. Does not have any effect if no cells are active in the grid.
Thank you for the reply.
The issue that I was facing with the igtbl_addNew() function was because the AddNewRowDefault was set as visible true. After setting this property as visible false, the igtbl_addNew() function started working as expected.