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

RadGrid won't sort some columns

5 Answers 535 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 02 Oct 2015, 05:07 PM

I am having trouble with the sort function on the RadGrid.  All columns are set to allow sorting, but only some columns work.  When I click on the  header, the grid repaints but nothing changes and the previous selected sort column remains highlighted with the sort icon visible.  It will not change to some of the columns.  In the same code,these columns will not sort:  Modified Date , Client Name and Proposal Type.  The remaining columns sort fine.

 

       <telerik:RadGrid ID="ProposalGrid" DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="False" AllowPaging="True" GroupingEnabled="False" Skin="Metro" OnItemDataBound="ProposalGrid_ItemDataBound"
            OnPreRender="ProposalGrid_PreRender" OnItemEvent="ProposalGrid_ItemEvent" CssClass="defaultText"
            OnDeleteCommand="ProposalGrid_DeleteCommand" OnUpdateCommand="ProposalGrid_UpdateCommand"
            OnPageSizeChanged="ProposalGrid_PageSizeChanged" PageSize="15" OnSortCommand="ProposalGrid_SortCommand"
            GroupPanelPosition="Top" ResolvedRenderMode="Classic" AllowMultiRowEdit="True" AllowMultiRowSelection="True" OnDataBound="ProposalGrid_DataBound" AllowSorting="True">
            <ClientSettings EnableRowHoverStyle="True">
                <Selecting AllowRowSelect="True"></Selecting>
            </ClientSettings>
            <MasterTableView DataSourceID="SqlDataSource1" ClientDataKeyNames="PropDesc" DataKeyNames="PropDesc"
                UseAllDataFields="True" TableLayout="Auto" EditMode="EditForms" NoDetailRecordsText="There are no cases for this workbook."
                NoMasterRecordsText="There are no cases for this workbook.">
                <PagerStyle AlwaysVisible="true" Wrap="False" PageButtonCount="5" ShowPagerText="True" />
                <SortExpressions>
                    <telerik:GridSortExpression FieldName="PropDesc" SortOrder="Ascending" />
                </SortExpressions>
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                    <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                   <HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridClientSelectColumn FilterControlAltText="Filter column1 column" UniqueName="column1" DataType="System.TimeSpan">
                    </telerik:GridClientSelectColumn>
                    <telerik:GridBoundColumn DataField="PropDesc" FilterControlAltText="Filter PropDesc2 column"
                        HeaderText="Storage Description" SortExpression="PropDesc" UniqueName="PropDescEditorCol"
                        Visible="False" ColumnEditorID="PropDescEditor" HeaderButtonType="None">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" />
                        <ItemStyle HorizontalAlign="Left" Wrap="False" />
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn FilterControlAltText="Filter ModifiedDate column"
                        HeaderText="Modified Date" ReadOnly="True" SortExpression="ModifiedDate" UniqueName="ModifiedDate">
                        <HeaderStyle Font-Bold="True" Wrap="False" />
                        <ItemStyle Wrap="False" HorizontalAlign="Left" />
                    </telerik:GridDateTimeColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter ClientName column"
                        HeaderText="Client Name" ReadOnly="True" SortExpression="ClientName" UniqueName="ClientName">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="100px" Wrap="False" />
                        <ItemStyle HorizontalAlign="Center" Width="100px" Wrap="False" />
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="PresentedBy" FilterControlAltText="Filter AgentName column" HeaderText="Agent Name" UniqueName="AgentNameCol" ColumnEditorID="AgentName" ReadOnly="True" SortExpression="AgentNameCol" EmptyDataText="">
                        <HeaderStyle Font-Bold="True" Wrap="False" />
                        <ItemStyle HorizontalAlign="Left" Width="150px" Wrap="False" />
                    </telerik:GridBoundColumn>
                    <telerik:GridHyperLinkColumn DataNavigateUrlFields="PropNumber,ClientNumber,ConceptProcNum"
                        DataNavigateUrlFormatString="Prop={0}&amp;ClientID={1}&amp;WP={2}&amp;Type=Edit"
                        DataTextField="PropDesc" FilterControlAltText="Filter column column" HeaderText="Storage Description"
                        UniqueName="PropDesc" SortExpression="PropDesc">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" Width="160px" />
                        <ItemStyle HorizontalAlign="Left" Wrap="False" Width="160px" />
                    </telerik:GridHyperLinkColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="Proposal Type"
                        ReadOnly="True" UniqueName="SalesConcept" SortExpression="SalesConcept">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" Width="100px" />
                        <ItemStyle HorizontalAlign="Left" Wrap="False" Width="100px" />
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="PolicyCaseNotation" FilterControlAltText="Filter column column"
                        HeaderText="Policy Notation" ReadOnly="True" SortExpression="PolicyCaseNotation"
                        UniqueName="PolicyCaseNotation" ItemStyle-Wrap="False">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" Width="120px" />
                        <ItemStyle HorizontalAlign="Left" Wrap="False" Width="120px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PolicyInitPremium" DataFormatString="{0:$#,0}"
                        FilterControlAltText="Filter column1 column" HeaderText="Initial Premium" ReadOnly="True"
                        SortExpression="PolicyInitPremium" UniqueName="PolicyInitPremium">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" Width="80px" />
                        <ItemStyle HorizontalAlign="Right" Wrap="False" Width="80px" />
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings PopUpSettings-Modal="True" FormCaptionStyle-Wrap="False">
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormCaptionStyle Wrap="False"></FormCaptionStyle>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                    <PopUpSettings Modal="True"></PopUpSettings>
                </EditFormSettings>
            </MasterTableView>
            <HeaderStyle Wrap="False" />
            <PagerStyle AlwaysVisible="True" Mode="NextPrevNumericAndAdvanced" />
            <SelectedItemStyle Font-Bold="True" />
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
        </telerik:RadGrid>

​

5 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 07 Oct 2015, 01:40 PM
Hello Richard,

Could you temporarily disable any AJAX on the page if present (RadAjaxManager, RadAjaxPanel, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script or server errors interfering?

If there are no errors, I can prepare a sample RadGrid web site based on the provided mark-up and send it back to you.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Richard
Top achievements
Rank 1
answered on 07 Oct 2015, 05:43 PM

Turning off Ajax did generate an error.  I found that on the AgentNameCol if I change the sort expression to the same text as the DataField, the sort now works for the AgentNameCol.  However, I am getting an error on the Template Columns.  Below is the error I get when clicking on the SalesConcept column (column header is Proposal Type).  I get the same error on all the template columns.  Is there something I have to do for those column types?

 

 

Server Error in '/' Application.

Cannot find column SalesConcept. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Cannot find column SalesConcept.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[IndexOutOfRangeException: Cannot find column SalesConcept.] System.Data.DataTable.ParseSortString(String sortString) +5313286 System.Data.DataView.CheckSort(String sort) +35 System.Data.DataView.set_Sort(String value) +115 System.Web.UI.WebControls.FilteredDataSetHelper.CreateFilteredDataView(DataTable table, String sortExpression, String filterExpression, IDictionary filterParameters) +113 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1829 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138 Telerik.Web.UI.GridTableView.PerformSelect() +38 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30 Telerik.Web.UI.GridTableView.DataBind() +388 Telerik.Web.UI.GridSortCommandEventArgs.ExecuteCommand(Object source) +346 Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +205 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +71 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +147 Telerik.Web.UI.GridItem.FireCommandEvent(String commandName, Object commandArgument) +88 Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +7054 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9672326 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 ​

0
Eyup
Telerik team
answered on 12 Oct 2015, 12:28 PM
Hello Richard,

Could you verify that you are setting the SortExpression property of the columns:
<telerik:GridTemplateColumn DataField="ShipCountry"
    FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry"
    SortExpression="ShipCountry" UniqueName="ShipCountry">
</telerik:GridTemplateColumn>

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Richard
Top achievements
Rank 1
answered on 12 Oct 2015, 05:12 PM

The Sort Expression is set: SortExpression="SalesConcept"

Below is the code for this column:

 

<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="Proposal Type"
            ReadOnly="True" UniqueName="SalesConcept" SortExpression="SalesConcept">
            <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="False" Width="100px" />
            <ItemStyle HorizontalAlign="Left" Wrap="False" Width="100px" />

  </telerik:GridTemplateColumn>​

0
Eyup
Telerik team
answered on 15 Oct 2015, 11:25 AM
Hi Richard,

You can also add the DataField="SalesConcept" property to the column definition. In fact, I've created a sample RadGrid web site using the provided mark-up to demonstrate that the sorting should work as expected. Please run the attached application and let me know about the result on your side.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Richard
Top achievements
Rank 1
Share this question
or