Hello!
I would like to select the first row of a WebDataGrid upon load in javascript. I am calling the following function in the 'SelectionClientEvents -> Initialize' event.
function SelectRow(){var grid = document.getElementById('<%=wdgASNList.ClientID%>');var gridRow = grid.get_rows().get_row(0);grid.get_behaviors().get_selection().get_selectedRows().add(gridRow); }
I am receiving the "Object doesn't support this property or method" error at var gridRow = grid.get_rows().get_row(0);
Perhaps I am doing something wrong!
Thanks for all the help!
John
great!, it helped!
Hi,
In order to do this, handler the Grid's Initialize event instead, when you try to do it in the Selection's Initialize event, the behavior has not finished initializing yet. You can do this like so:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Width="400px" Height="400px"> <Behaviors> <ig:Selection RowSelectType="Multiple"> </ig:Selection> </Behaviors> <ClientEvents Initialize="GridInit" /> </ig:WebDataGrid>
function GridInit(grid, evntArgs){ var row = grid.get_rows().get_row(0); grid.get_behaviors().get_selection().get_selectedRows().add(row);}
Thank You,
Olga
John,
You need to find the grid as its JavaScript object, not just a DOM element in order to access its methods. Additionally, trying to select the row in the Selection behavior's initialize event means selection isn't ready yet. You can do this in the grid's initialize event.
function SelectRow() { var grid = $find("WebDataGrid1"); // my DataGrid has an Id of WebDataGrid1 var gridRow = grid.get_rows().get_row(0); grid.get_behaviors().get_selection().get_selectedRows().add(gridRow); }
<ClientEvents Initialize="SelectRow" />
regards,Dave Young