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

[Solved] Ajaxified RadGrid SortExpression Out of Range on Repeated Sorts

5 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil DeVeau
Top achievements
Rank 1
Phil DeVeau asked on 12 Jun 2009, 03:39 PM

I'm using an ajaxified RadGrid to display a long List<T> in a multi-tier environment.  I've implemented a custom paging solution and I'm passing the SortExpressions[0] information to my next tier.  This works fine for the first few sorts then I start to get an argument out range expression.

<telerik:RadGrid ID="AccountListRadGrid" runat="server" 
    OnItemCreated="AccountListRadGrid_ItemCreated" 
    OnItemCommand="AccountListRadGrid_ItemCommand" 
    OnItemDataBound="AccountListRadGrid_NodeDataBound" 
    OnNeedDataSource="AccountListRadGrid_NeedDataSource" 
    OnDeleteCommand="AccountListRadGrid_DeleteButton_Click" 
    SkinID="ObjectList" 
    GridLines="None" 
    AutoGenerateColumns="False" 
    AllowPaging="False" 
    AllowMultiRowSelection="true" 
    AllowSorting="True">  
    <MasterTableView   
            CommandItemDisplay="Bottom" 
            AllowPaging="false" 
            DataKeyNames="ObjectId">  
        <NoRecordsTemplate> 
            <div>There are no accounts to display</div> 
        </NoRecordsTemplate> 
        <CommandItemTemplate />   
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridTemplateColumn SortExpression="AccountName" HeaderText="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Account Name" UniqueName="AccountNameColumn">  
                <ItemTemplate> 
                    &#160;  
                    <asp:Image ID="TypeImg" ImageUrl="~/Images/50_ico.gif" runat="server" ImageAlign="AbsMiddle" /> 
                    &#160;  
                    <asp:Hyperlink runat="server" ID="NameLink" /> 
                </ItemTemplate> 
                <HeaderStyle Width="30%" /> 
            </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn DataField="FriendlyName" SortExpression="FriendlyName" HeaderText="Friendly Name" UniqueName="FriendlyNameColumn">  
                <HeaderStyle Width="30%" /> 
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="DateLastModified" SortExpression="DateLastModified" HeaderText="Date&#160;of&#160;Last&#160;Upload" UniqueName="LastModifiedColumn">  
                <HeaderStyle Wrap="false" /> 
                <ItemStyle Wrap="false" /> 
            </telerik:GridBoundColumn> 
            <telerik:GridNumericColumn DataField="ItemCount" HeaderText="Items" DataType="System.Int32" UniqueName="ItemCountColumn">  
                <HeaderStyle Wrap="false" Width="55px" HorizontalAlign="Center" /> 
                <ItemStyle Wrap="false" HorizontalAlign="Center" /> 
            </telerik:GridNumericColumn> 
            <telerik:GridButtonColumn ImageUrl="~/images/delete.gif" HeaderText="All:" CommandName="Delete" ConfirmText="Deactivate this Account?" ConfirmTitle="Deactivate Account" ConfirmDialogType="RadWindow" UniqueName="DeleteAccountColumn" ButtonType="ImageButton">  
                <HeaderStyle Wrap="false" HorizontalAlign="Right" Width="35px" /> 
                <ItemStyle HorizontalAlign="Center" /> 
            </telerik:GridButtonColumn> 
            <telerik:GridClientSelectColumn HeaderStyle-Width="20px" UniqueName="RevokeCheck"></telerik:GridClientSelectColumn> 
            <telerik:GridBoundColumn DataField="ObjectID" Display="False" UniqueName="IdColumn"></telerik:GridBoundColumn> 
        </Columns> 
        <SortExpressions> 
            <telerik:GridSortExpression FieldName="AccountName" SortOrder="Ascending" /> 
        </SortExpressions> 
        <CommandItemTemplate> 
            <div class="MoreRecordsContainer">  
                <asp:HyperLink ID="MoreRecords" runat="server" Text="More..." CssClass="MoreRecords" /> 
            </div> 
        </CommandItemTemplate> 
    </MasterTableView> 
    <ClientSettings Selecting-AllowRowSelect="true"></ClientSettings> 
</telerik:RadGrid> 
 public LPDataPageRequest DataPageRequest  
    {  
        get 
        {  
            RadGrid grid = AccountListRadGrid;  
            int currentPage = 0;  
            int pageSize = 15;  
            string property = string.Empty;  
            LPSortOrder sortOrder = LPSortOrder.Ascending;  
 
            if (grid.MasterTableView.SortExpressions != null && grid.MasterTableView.SortExpressions.Count > 0)  
            {  
                property = grid.MasterTableView.SortExpressions[0].FieldName;  
                sortOrder = grid.MasterTableView.SortExpressions[0].SortOrder == GridSortOrder.Ascending ? LPSortOrder.Ascending : LPSortOrder.Descending;  
            }  
 
            return new LPDataPageRequest(currentPage, pageSize, property, sortOrder);  
        }  
    } 

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 17 Jun 2009, 08:42 AM
Hi Phil,

I reviewed the code, and it looks correct.
However, based on this information, it is hard to determine what is causing the unwanted behavior.
If the issue persists, you can open a formal support ticket, and send us the problematic code, in the form of a small working project. We will review it locally, and advise you further.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Phil DeVeau
Top achievements
Rank 1
answered on 18 Jun 2009, 02:57 PM
The problem appears to be that I'm setting an item as sorted to start, so through continued sorts the pattern of sortexpressions sorting the same field, starting from ascending, is field asc, field desc, none.  When the sortorder is non sortexpressions[0] is null.  Is there a declarative way to disallow the sortorder none case, or does that have to be handled in code?
0
Yavor
Telerik team
answered on 22 Jun 2009, 10:37 AM
Hello Phil,

You can disallow natural sort (sort = none), by setting AllowNaturalSort="false".
Let me know how this works in your case.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Phil DeVeau
Top achievements
Rank 1
answered on 22 Jun 2009, 02:01 PM
Thanks for the tip, this worked in my sample project, so it should work in my actual project.  I've got a skin file set up, I wonder if I could integrate that into my radgrid skin, this way I won't have to hit each radgrid on each user control.
0
Yavor
Telerik team
answered on 23 Jun 2009, 01:23 PM
Hi Phil,

If you are looking to alter a specific skin for the grid, the following article contains additional information. I hope it gets you started properly.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Phil DeVeau
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Phil DeVeau
Top achievements
Rank 1
Share this question
or