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

Default Sorting

1 Answer 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karthi
Top achievements
Rank 1
Karthi asked on 11 Mar 2011, 06:04 AM
I have a column named 'Unread' in my Rad grid. Please see the following aspx code.

<Telerik:RadGrid ID="MessageBoardRadGrid"  Width="100%" AllowSorting="True" PageSize="15" AllowPaging="True" 
              AllowMultiRowSelection="True" runat="server" Gridlines=Both  HeaderStyle-Font-Bold=true 
              AutoGenerateColumns="False"  >
               <PagerStyle Mode="NextPrevAndNumeric" />                  
               <MasterTableView DataKeyNames="Name" AutoGenerateColumns="false">
                   <Columns>                           
                       <Telerik:GridTemplateColumn  DataField="Unread" HeaderText="Unread" HeaderStyle-CssClass="gridheader">                    
                           <ItemTemplate>
                               <%# Formatter.StatusIcon( (Forum) Container.DataItem ) %>
                           </ItemTemplate>
                       </Telerik:GridTemplateColumn >

I am binding an image if there is an most resent update on the column.
Please find the code for the StatusIcon() method below.
if (forum.LastUserActivity < forum.MostRecentPostDate) 
        {
            icon = "forum_status_new_ln.gif";
            alt = ResourceManager.GetString("IconAlt_NewPosts");
        }

I want to make it a default sorted column to show the unread items first.
Kindly help me accomplishing this.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Mar 2011, 07:08 AM
Hello Karthi,

To enable sorting for GridTemplateColumn, you need to set appropriate SortExpression values that should match the data field you want to sort on (typically the field a control in the template is bound to).

<telerik:GridTemplateColumn DataField="Unread" SortExpression="Unread" HeaderText="Unread">
     <ItemTemplate>
        .   .    .    .
     </ItemTemplate>
</telerik:GridTemplateColumn>

More information about sorting GridTemplateColumn is available here:
Sorting for GridHyperLinkColumn/GridTemplateColumn

And to achieve default sorting , add appropriate sort expression.
<MasterTableView CommandItemDisplay="Top">
     <SortExpressions>
         <telerik:GridSortExpression FieldName="Unread" SortOrder="Ascending" />
     </SortExpressions>

Thanks,
Princy.
Tags
Grid
Asked by
Karthi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or