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

Iterating over first columns in a grouped RadGrid

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 24 Oct 2016, 01:04 PM

I have a RadGrid in which i need to loop through the first column and turn off the on click event.  

Prior to grouping this RadGrid the following code did this across each individual row.

CType(CType(Page.Form.FindControl("ReportGrid"), RadGrid).MasterTableView.Items(i).Cells(2), TableCell).Attributes.Add("OnClick", "return false;")

And 

CType(Page.Form.FindControl("ReportGrid"), RadGrid).MasterTableView.Items(lastRowCount - j).CssClass = "boldRow" 

over the last row in order to bold the sum row. 

 

However now with grouping I cannot locate the appropriate position to set the attribute/cssclass.  Also the total row for each group is duplicated twice. 

How do I access the first column in each row turn off the OnClick event? And how do I find/access the last row of each group? 

thank you. 

<telerik:RadGrid ID="ReportGrid" runat="server" AllowSorting="True" AutoGenerateColumns="False"
Skin="Rental" PageSize="100000" GridLines="None" Width="930px" AllowPaging="True"
TabIndex="-1" EnableEmbeddedSkins="false" Height="480px" >
<PagerStyle Position="Bottom" Mode="NumericPages" PageButtonCount="10" AlwaysVisible="true" />
<ClientSettings>
<Scrolling UseStaticHeaders="True" AllowScroll="True" ScrollHeight="430px"></Scrolling>
<Resizing ResizeGridOnColumnResize="True" ClipCellContentOnResize="False" />
</ClientSettings>
<SortingSettings EnableSkinSortStyles="false" />
<MasterTableView AllowCustomSorting="true" AllowMultiColumnSorting="false" EnableNoRecordsTemplate="False" GridLines="Vertical" DataKeyNames="regionid" TableLayout="Fixed">
<SortExpressions>
<telerik:GridSortExpression FieldName="Product" SortOrder="Ascending" />
</SortExpressions>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="Product" FieldName="Product" SortOrder="Ascending"></telerik:GridGroupByField>
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldName="ProductSort" SortOrder="Descending"></telerik:GridGroupByField>
</GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<NoRecordsTemplate>
There is no data to display.
</NoRecordsTemplate>
<Columns>
<telerik:GridButtonColumn ButtonType="LinkButton" ImageUrl="" HeaderText="Region"
DataTextField="RegionName" ItemStyle-CssClass="GrdBtn" CommandName="Select" UniqueName="btnSelect" SortExpression="Name"
HeaderStyle-Width="150px" />
<telerik:GridBoundColumn DataField="Size" HeaderText="Size" UniqueName="Size"
SortExpression="Util">
<HeaderStyle Width="60px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Util" HeaderText="Util" UniqueName="Util"
SortExpression="Util">
<HeaderStyle Width="60px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Lol" HeaderText="Lol" UniqueName="Lol"
SortExpression="Lol">
<HeaderStyle Width="60px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ConLength" HeaderText="ConLength over Time" UniqueName="ConLength"
SortExpression="ConLength">
<HeaderStyle Width="60px" />
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 27 Oct 2016, 10:42 AM
Hi,

Accessing the column cells is possible by setting a UniqueName for the column and doing the following.
CType(CType(Page.Form.FindControl("ReportGrid"), RadGrid).MasterTableView.Items(i)("thecolumnuniquename"), TableCell).Attributes.Add("OnClick", "return false;")

As for adding a class for the last row in the group on the server I have to say that this would be difficult. However you can easily achieve this on the client using jQuery. An exemplary implementation is provided below.
function pageLoad() {
    $telerik.$(".rgRow,.rgAltRow").each(function () {
        var that = this;
 
        if (that.nextSibling.className && that.nextSibling.className.indexOf("rgGroupHeader") !== -1) {
            $telerik.$(that).addClass("boldRow");
        }
 
        if (!that.nextSibling.className && $telerik.$(".rgGroupHeader").last().text().indexOf("continues") == -1) {
            $telerik.$(that).addClass("boldRow");
        }
    });
}


Regards,
Angel Petrov
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or