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

RadGrid page sorting incorrect

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
-glenn-
Top achievements
Rank 1
-glenn- asked on 19 Aug 2010, 05:41 PM
I have a RadGrid on an ASP.NET page and the sorting of the rows for each page does not always work properly. For example, I have one grid with 359 rows, the grid's page size is 50, and the column being sorted is a DateTime field. So for 359 rows at 50 each the grid properly breaks things up into 8 pages. When you go to pages 1-4 and 6-8, each page's rows are properly sorted in descending order. When you go to page 5 the rows seemed to be sorted by "date string" order, instead of being sorted the normal DateTime way they sure appear to be sorted in their string order (where the format is "MM/DD/YYYY").

I've used SQL Manager to look at the data returned from the query and each page appears to have the proper rows, just page 5 is not sorted correctly. The control is fed the entire set of data (all 359 rows) any time "needs data" is called, so it is the control that is figuring out which 50 of the set need to be displayed and in what order.

Here's what I think is the pertinent markup:

<telerik:RadGrid ID="InvoicesGrid" runat="server" Skin="Sullivans" EnableEmbeddedSkins="false"
    CellPadding="3" GridLines="None" AlternatingItemStyle-CssClass="orderAltRow"
    AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
    AllowPaging="True" OnNeedDataSource="InvoicesGrid_NeedDataSource" OnItemDataBound="InvoicesGrid_ItemDataBound"
    OnPageIndexChanged="InvoicesGrid_PageIndexChanged">
    <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
    <MasterTableView Width="100%" DataKeyNames="Header.Invoice_No" AllowMultiColumnSorting="False" ShowFooter="true" AllowNaturalSort="False">
        <Columns>
 
<!-- Bunch of columns removed. -->
 
            <telerik:GridBoundColumn DataField="Header.Invoice_Dt" HeaderText="Date" DataFormatString="{0:d}" Aggregate="None" DataType="System.String" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

I added the AllowNaturalSort="False" to the MasterTableView today; I get the same results with or without that tag.

The only binding of the control is when the page is initialized, and in that case a Rebind is called.

The "need data" event simply gets the data from the database into an array of class objects and is bound like this:

InvoicesGrid.DataSource = details;

The item data bound formats some columns, but doesn't touch the date column.

Any ideas appreciated, and if I can supply any further info please let me know.

1 Answer, 1 is accepted

Sort by
0
-glenn-
Top achievements
Rank 1
answered on 19 Aug 2010, 05:51 PM
OK, so I'm blind. I would have sworn I had the DataType of the date column set to DateTime - but as I was proof-reading my post I saw it was set to String. Setting it to DateTime not only fixes the sorting but also explains the "problem."

This is only my second post to this forum and I answered my first post shortly after posting that one too. You guys are good; just by posting the problem is figured out. :-)
Tags
Grid
Asked by
-glenn-
Top achievements
Rank 1
Answers by
-glenn-
Top achievements
Rank 1
Share this question
or