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

RadGrid Can I Restrict Sorting="false" On A GridTemplateColumn

2 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sir
Top achievements
Rank 1
Sir asked on 18 Jul 2008, 07:50 PM
I have a simple grid with 2 bound columns and 1 unbound column.

My unbound column has a label that is populated server side from some stringbuilder data where sorting would not make sense.

I can set AllowSorting="false" on the bound columns but not the unbound column.
So the unbound column, which I do not want sorting enabled, is rendered with a sortable header link.
Why doesn't the unbound column have the AllowSorting property? I think it would make a lot of sense to have that for an unbound column.

Right now, server side, I am having to delve into all the child controls of the grid till I get the sorting header LinkButton for that column and then I set OnClientClick="return false;"

Is there an easy way to turn off sorting for just the unbound GridTemplateColumn while still being able to sort the bound columns?


here's my grid:

<RadControl:RadGrid ID="RadGridUsers" runat="server" Skin="Default" Width="511px" Height="564px" BorderWidth="0" GridLines="None" AutoGenerateColumns="False" ShowGroupPanel="False" AllowPaging="False" AllowSorting="True" EnableEmbeddedSkins="false">

<ClientSettings ReorderColumnsOnClient="False" AllowDragToGroup="False" AllowColumnsReorder="False" Selecting-AllowRowSelect="true">

<Scrolling AllowScroll="true" UseStaticHeaders="true" />

<Selecting AllowRowSelect="True"></Selecting>

<Resizing AllowRowResize="False" EnableRealTimeResize="False" ResizeGridOnColumnResize="False" AllowColumnResize="False"></Resizing>

<ClientEvents OnRowSelected="RadGrid_RowSelected" /></ClientSettings>

<MasterTableView DataKeyNames="UserProfileId,FidelityId" ClientDataKeyNames="UserProfileId,FidelityId" GroupLoadMode="Client" AllowMultiColumnSorting="False" AllowNaturalSort="false">

<SortExpressions>

<RadControl:GridSortExpression FieldName="LearningCenterId" SortOrder="Ascending" />

</SortExpressions>

<NoRecordsTemplate>

<div style="text-align: center; height: 300px">

<asp:Label ForeColor="RoyalBlue" Font-Size="14" runat="server" ID="Label1">There are no items to display</asp:Label>

<br />

</div>

</NoRecordsTemplate>

<Columns>

<RadControl:GridBoundColumn UniqueName="Name" SortExpression="Name" HeaderText="Employee Name" DataField="Name" ShowSortIcon="true">

<HeaderStyle Width="25%" Wrap="false" HorizontalAlign="left" VerticalAlign="Middle"></HeaderStyle>

<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>

</RadControl:GridBoundColumn>

<RadControl:GridTemplateColumn UniqueName="Details" SortExpression="Details" HeaderText="Details" ShowSortIcon="false">

<HeaderStyle Width="50%" Wrap="false" HorizontalAlign="left" VerticalAlign="Middle"></HeaderStyle>

<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>

<ItemTemplate>

<asp:Label ID="lblGridDetails" runat="server" Text="&nbsp;"></asp:Label>

</ItemTemplate>

</RadControl:GridTemplateColumn>

<RadControl:GridBoundColumn UniqueName="Title" SortExpression="Title" HeaderText="Title" DataField="Title" ShowSortIcon="true">

<HeaderStyle Width="25%" Wrap="false" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>

<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>

</RadControl:GridBoundColumn>

</Columns>

</MasterTableView>

</RadControl:RadGrid>



Thanks,
RjD

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jul 2008, 04:34 AM
Hi RjD,

Try removing the SortExpression for the GridTemplateColumn and see whether it is comming as expected.

ASPX:
<RadControl:GridTemplateColumn UniqueName="Details" SortExpression="" HeaderText="Details" ShowSortIcon="false"
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle> 
     <ItemTemplate> 
       <asp:Label ID="lblGridDetails" runat="server" Text="&nbsp;"></asp:Label> 
     </ItemTemplate> 
</RadControl:GridTemplateColumn> 


Thanks
Shinu.
0
Sir
Top achievements
Rank 1
answered on 21 Jul 2008, 10:05 PM
Thanks so much!
That's the trick.

I had removed the SortExpression property before and the whole column is left out of the output...

but setting SortExpression to an empty string is the magic I was looking for.

RjD
Tags
Grid
Asked by
Sir
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sir
Top achievements
Rank 1
Share this question
or