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

Grid Sorting Issue - Weird

4 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sameers
Top achievements
Rank 1
Sameers asked on 10 Nov 2010, 11:48 AM
This is the first time I see such issue. There must be something wrong I couldn't figure out.

I am sorting on a column of type Decimal. But it doesn't sort values properly. Please see attached. Below is my code!

<telerik:RadGrid ID="grdMain" runat="server" GridLines="None" Width="100%" AllowSorting="true">
                                        <ExportSettings>
                                            <Pdf PageWidth="8.5in" PageHeight="11in" PageTopMargin="" PageBottomMargin="" PageLeftMargin=""
                                                PageRightMargin="" PageHeaderMargin="" PageFooterMargin=""></Pdf>
                                        </ExportSettings>
                                        <MasterTableView AutoGenerateColumns="False" HierarchyDefaultExpanded="true" ExpandCollapseColumn-CollapseImageUrl="~/images/trans.gif">
                                            <RowIndicatorColumn Visible="False">
                                                <HeaderStyle Width="20px"></HeaderStyle>
                                            </RowIndicatorColumn>
                                            <ExpandCollapseColumn Visible="False" Resizable="False">
                                                <HeaderStyle Width="20px"></HeaderStyle>
                                            </ExpandCollapseColumn>
                                            <SortExpressions>
                                                <telerik:GridSortExpression FieldName="Rate" />
                                            </SortExpressions>
                                            <Columns>
                                                <telerik:GridTemplateColumn HeaderText="Carrier" SortExpression="Carrier">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblCarrier" runat="Server" Text='<%#Eval("Carrier")%>'></asp:Label>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="APICode" Visible="false">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblAPICode" runat="Server" Text='<%#Eval("MailServiceCode")%>'></asp:Label>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="Code" Visible="false">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblCode" runat="server" Text='<%#Eval("LocalShipServiceCode")%>'></asp:Label>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="Name" SortExpression="MailService">
                                                    <ItemTemplate>
                                                        <%#Eval("MailService")%>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="Rate" SortExpression="Rate">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblRate" runat="server" Text='<%#FormatCurrency(Eval("Rate"), 2)%>'></asp:Label>                                                        
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="btnSelect" runat="server" Text="Select" CommandName="Select"
                                                            CommandArgument='<%# eval("LocalShipServiceCode") & "," & eval("Rate") & "," & eval("Carrier") %>'></asp:LinkButton>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>

The sort thing was just a piece of cake in RadGrid, but for some reason, it is a mess. I am binding the grid in NeedDataSource event as

Me

 

.grdMain.DataSource = CType(Session("rates"), Generic.List(Of Core.Shipping.RateEstimate.ShippingEstimate))

 


Where ShippingEstimate is a class with some properties (as bound to grid).
Any Idea why it is not sorting properly?

thanks,
Sameers

4 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 11 Nov 2010, 11:01 AM
Hello Sameers,

It is actually sorted alphabetically as strings. This suggest that your Rate column is not proper data type, and it is string instead of decimal.

Make sure the datasource you are using returns Rate as decimal type. And set the DataType property in your GridTemplateColumn.

Also set the DataType property for the Rate column
<telerik:GridTemplateColumn HeaderText="Rate" SortExpression="Rate" DataType="System.Decimal">

Sincerely yours,
Vasil
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sameers
Top achievements
Rank 1
answered on 11 Nov 2010, 11:06 AM
I can understand that. the column IS of type Decimal.

Even after adding DataType to grid column definition, I see no change in sorting. Its still not sorting properly.

Any other idea?

thanks,
Sameers
0
Sameers
Top achievements
Rank 1
answered on 11 Nov 2010, 04:08 PM
My bad!

Although the private variables data type was Decimal, but by mistake, the Propert returns String (data type string). So I guess grid was considering it string.

But I still wonder, as per your suggestio, when I set the data type to the grid column, why didn't it worked? Why I must had to fix the data type of property itself?

thanks again,
Sameers
0
Vasil
Telerik team
answered on 11 Nov 2010, 04:13 PM
Hi Sameers,

Check the attachment and see if it works properly for you.
If you still experience problem with sorting, please show me the declaration of the ShippingEstimate class.

All the best,
Vasil
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sameers
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Sameers
Top achievements
Rank 1
Share this question
or