Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1175
Sorting on TemplateFields
posted

Hello there,


the user should be able to sort some columns, this can be normal text (names), numbers or dates.

I found this example on your page: http://help.infragistics.com/Help/NetAdvantage/ASPNET/2012.1/CLR4.0/html/WebDataGrid_Sorting.html 

The example just binds directly to the data, in my case, I have Templates as columns:

                   

<ig:TemplateDataField Key="Name" Width="260px">

                       

<HeaderTemplate>

                           

<asp:Label ID="lblNameHeader" runat="server">Name</asp:Label><br>

                       

</HeaderTemplate>

                       

<ItemTemplate>

                           

<asp:LinkButton ID="linkBtnName" runat="server" CausesValidation="False" CommandName="Link"

                               

Width="200px" Font-Underline="true" Style="white-space: pre-wrap;">linkBtnName</asp:LinkButton>

                       

</ItemTemplate>

                       

<FooterTemplate>

                           

<div class="rowSelectEdit">

                               

<stgwc:TextEdit runat="server" ID="txtIndvId" Width="0px" />

                               

<asp:Label runat="server" ID="lblNameEdit" CssClass="lblRequiredField" Style="white-space: pre-wrap;">

                                                           

                               

</asp:Label>

                               

<stgwc:ImageLinkButton ID="ibutChange" runat="server" CssClass="icoButton" ToolTip="Opens a search page where you can find your roles entry."

                                   

CausesValidation="False" ImageUrl="Images/base/Icons/16x16/media_play_green.png"

                                   

CommandName="SearchIndOrgInsert">

                               

</stgwc:ImageLinkButton>

                           

</div>

                       

</FooterTemplate>

                   

</ig:TemplateDataField>

 

In the Code behind, I set the sorting like this:

       

       

private void InitializeSortButtons()

        {

            dgrRoles.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.

Sorting>();

            dgrRoles.Behaviors.Sorting.SortingMode =

SortingMode.Single;

            dgrRoles.Behaviors.Sorting.SortedColumns.Add(dgrRoles.Columns[COL_NAME], Infragistics.Web.UI.

SortDirection.Ascending);

            dgrRoles.Behaviors.Sorting.SortedColumns.Add(dgrRoles.Columns[COL_NAME], Infragistics.Web.UI.

SortDirection.Descending);

        }

 

const string COL_NAME = "Name";

 

But I get an error on the preRender:

"An unexpected error occured. Cannot find column Name."

 

 

Am I missing something? Is it possible to sort with the template fields?

 

 

BTW: Is there a possibility to format code better?

 

 

Thanks for your response!

 

Parents
  • 2783
    Verified Answer
    posted

    Hi Matthias,

    The WDG will not sort Templated columns by default, since in cases where the datasource is able to sort we use the datasource for sorting. Also the grid has no idea what part of the template is sortable, as in do we sort by the label text or label id or what if you have a  link, should the URL be sorted or the text, ect?

    You can implement sorting for your templated columns though, as you know which parts of the template should be sortable for your particular application/page. This can be achieved in multiple ways.  I am attaching two different websites which show you two different ways to implement it.

    1. TemplatesWithoutTemplatedField.zip – this site shows how you can set a Header Template, Footer Template and as well as a cell template for  a BoundDataField column. Since BoundDataField columns are sortable, sorting works by default. The templated column in this example renders sorted already as it is added to the SortedColumns  in Page_Load. (the cell template has to be set in the code behind)
    2. HiddenDataColumn.zip – this shows you how you can use a TemplateDataField, and a hidden BoundDataField column. It uses javascript and when the user goes to sort by clicking on the header of the templated column, instead of allowing sorting to add the templated column to the SortedColumns collection it adds the hidden BoundDataField column.

     

     

    In order to run the attach sample please change the Infragistics dll reference in the Web.Config and ASPX files to the version that you are currently using. Currently the style directory is set in the Web.Config file to be located in "http://localhost/ig_res12.1" virtual directory, if this is not where you have your Infragisitcs styles installed please change this as well.

     

    Thank You,

    Olga

    ASP.NET Principal Software Engineer

    Infragistics, Inc.

    TemplatesWithoutTemplatedField.zip
Reply Children