This is a migrated thread and some comments may be shown as answers.

Loop row collection of grid (in clientside) using GridGroupByExpression

4 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nabil
Top achievements
Rank 1
Nabil asked on 17 Jan 2009, 07:56 AM
I have Q2 2008 controls. I have populate grid with data which is using GridGroupByExpression. Kindly give me clientside script which:

1- returns me row collection
2- Controls with in cell of row

4 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 19 Jan 2009, 04:46 PM
Hello Nabil,

Straight onto your questions:

  1. The get_dataItems() collection will return the number of data items in the grid (excluding the group headers). Review the following topic from the online documentation which provides an overview of the client-side object model of RadGrid for ASP.NET AJAX:
    http://www.telerik.com/help/aspnet-ajax/grdgettingfamiliarwithclientapi.html
  2. To locate controls within a row cell client-side, consider utilizing the findControl/findElement methods from the client API of the grid.
Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nabil
Top achievements
Rank 1
answered on 20 Jan 2009, 05:18 AM
Thanks for the Clientside API. Consider the following example.

Grid is populated with data and GroupBy some column. Server side button is used to save data of Grid. But before calling serverside function I want to do something on client side. I write following to get the grid:

var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();

var rows = masterTable.get_dataItems(); // row collection

But this returns me null. When I remove GridGroupByExpression then it gives me row collection. Also you have given me example to get the control on RadGrid1_RowDataBound event. Kindly give me the solution for above serverside button control.

0
Sebastian
Telerik team
answered on 20 Jan 2009, 03:44 PM
Hello Nabil,

I tested the following example (see the code below) and the get_dataItems() collection of the grid returned the expected set of items:

            <script type="text/javascript">  
            function OperateWithGridRows()  
            {  
  
              var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();  
              var rows = masterTable.get_dataItems();   
                
              var firstRow = rows[0];  
              //here you can call the findControl or findElement method for the firstRow instance  
            }  
            </script> 
            <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" Width="97%" 
                PageSize="20" AllowSorting="True" AllowMultiRowSelection="True" Skin="Outlook" 
                AllowPaging="True" ShowGroupPanel="True" AutoGenerateColumns="False" GridLines="none">  
                <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle> 
                <MasterTableView Width="100%">  
                    <GroupByExpressions> 
                        <telerik:GridGroupByExpression> 
                            <SelectFields> 
                                <telerik:GridGroupByField FieldAlias="Received" FieldName="Received" FormatString="{0:D}" 
                                    HeaderValueSeparator=" from date: "></telerik:GridGroupByField> 
                            </SelectFields> 
                            <GroupByFields> 
                                <telerik:GridGroupByField FieldName="Received" SortOrder="Descending"></telerik:GridGroupByField> 
                            </GroupByFields> 
                        </telerik:GridGroupByExpression> 
                    </GroupByExpressions> 
                    <Columns> 
                        <telerik:GridBoundColumn SortExpression="Received" HeaderText="Received" HeaderButtonType="TextButton" 
                            DataField="Received" DataFormatString="{0:d}">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn SortExpression="From" HeaderText="From" HeaderButtonType="TextButton" 
                            DataField="From">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn SortExpression="FolderName" HeaderText="Folder name" HeaderButtonType="TextButton" 
                            DataField="FolderName">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn SortExpression="Size" HeaderText="Size" HeaderButtonType="TextButton" 
                            DataField="Size">  
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
                <ClientSettings AllowDragToGroup="True">  
                </ClientSettings> 
            </telerik:RadGrid> 
            <input id="Button1" type="button" value="Check items" onclick="OperateWithGridRows()" /><br /> 
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" 
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Mails" runat="server">  
            </asp:SqlDataSource> 

Can you please test the sample on your machine to see the effect? Note that there is a comment in the code how to reference RadControl or html element (using the findControl or findElement client methods) for the first item in the grid.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nabil
Top achievements
Rank 1
answered on 21 Jan 2009, 05:14 AM
Thanks for the detail. I have checked my code again. Its my mistake. Actually property 

 GroupsDefaultExpanded="False"

was set that is why it was returning nothing in clientside.

Thanks again.
Tags
Grid
Asked by
Nabil
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Nabil
Top achievements
Rank 1
Share this question
or