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

Sorting not working

10 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BV
Top achievements
Rank 1
BV asked on 17 Jun 2010, 04:24 PM

Please lookinto my code below

<MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" 
                            HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" 
                            BorderWidth="1px" AllowSorting="true" AutoGenerateColumns="False">  
                            <RowIndicatorColumn> 
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn> 
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                            <ItemStyle BackColor="LightGray" /> 
                            <HeaderStyle BackColor="#1C5E55" /> 
                            <CommandItemStyle Font-Names="tahoma" Font-Size="10pt" /> 
                            <Columns> 
                                  
                                <telerik:GridBoundColumn UniqueName="WorkflowType" SortExpression="WorkflowType" 
                                    HeaderText="Workflow Type" DataField="WorkflowType">  
                                </telerik:GridBoundColumn> 
                                  
                            </Columns> 
                        </MasterTableView> 

This is my code. The sort is not ascending or descending correctly for workflow column. But records are ordered in some random manner. Can any one please guide.

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jun 2010, 11:59 AM
Hello,

If you are automatically sort the RadGrid by setting AllowSorting property to True, then it allow users to select a sorting mode like Ascending/Decending/No sort. You can set default sort expression for the MasterTableView directly in the ASPX declaration to provide an initial sort order.

ASPX:


 
<MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" 
                HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" 
                BorderWidth="1px" AllowSorting="true" AutoGenerateColumns="False"
                <SortExpressions> 
                    <telerik:GridSortExpression FieldName="WorkflowType" SortOrder="Ascending" /> 
                </SortExpressions> 
      ................................. 

Thanks,
Princy.
0
BV
Top achievements
Rank 1
answered on 18 Jun 2010, 12:03 PM
Thanks for you reply.. But my problem is I want all the 3 sorts. If the sort is in ascending/descending it is not getting sorted correctly.
0
Pavlina
Telerik team
answered on 21 Jun 2010, 10:03 AM
Hi Bino,

I followed your scenario in order to replicate the issue but to no avail. However I am sending you a simple runnable project which handles the desired functionality. Please give it a try and let me know what is the difference in your scenario. 

Kind regards,
Pavlina
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
BV
Top achievements
Rank 1
answered on 23 Jun 2010, 02:20 PM

Thanks for your reply. Can you please answer my below queries

1. Grid sorting is not working ,if I have listitem as datasource to telerik grid ,. However if I convert the same list as an datatable and bind it as a datasource , the sorting is working correctly. Do the datatype of datasource matters in sorting ?

2. I have a value from database( For instance say "EDIT" , "ADD") now if I convert "ADD" in codebehind  to "Sucessfully added",  and bind it in grid. How to make the sort work for the converted string ( like if I sort in ascending order, I want in the order of EDIT, Sucessfully added ?

Since the SortExpression of my grid is set to my database value my asc sort is returning in the order  Sucessfully added , EDIT.


Thanks
Bino

0
Pavlina
Telerik team
answered on 25 Jun 2010, 03:26 PM
Hello BV,

It would be best if you could open a formal support ticket and send us a simple running project that demonstrates your scenario with detailed information on the problem. We will take a look at your code, test it on our side, investigate the issues and do our best to help you.

All the best,
Pavlina
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
BV
Top achievements
Rank 1
answered on 25 Jun 2010, 04:43 PM
Thanks for your reply..
  
I will customize and send you my sample code. Can you please tell me,  if changing the value in ItemDataBound event of the grid, makes the sorting behave incorrectly?
because When I bind a proper datatable to the Grid, whithout having any ItemDataBind Event the sorting works correctly

Thanks
Bino
0
Pavlina
Telerik team
answered on 30 Jun 2010, 10:07 AM
Hi Bino,

I think that changing the value in ItemDataBound event of the grid should not cause the sorting behave incorrectly. However, I am looking forward to receiving the requested application.

Sincerely yours,
Pavlina
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
BV
Top achievements
Rank 1
answered on 02 Jul 2010, 03:41 PM
Hi Pavlina,
Thanks for your reply. Please find my code used below.

Thanks in advance for your solution

My Aspx page

<telerik:RadGrid ID="rgTopics" AutoGenerateColumns="True" runat="server" AllowPaging="true" 
                        PageSize="20" AllowSorting="true" OnPageIndexChanged="radgridWorkflowResults_SelectedIndexChanged" 
                        OnSortCommand="radgridWorkflowResults_OnSort" Skin="Web20" SelectedItemStyle-BackColor="LightBlue" 
                        CommandItemStyle-Font-Names="tahoma" BorderColor="White" GridLines="None"   
                        OnPageSizeChanged="radgridWorkflowResults_OnPageSizeChanged" OnItemDataBound="rgTopics_ItemDataBound">  
                        <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="True" ></PagerStyle>  
                        <SelectedItemStyle BackColor="LightBlue" /> 
                        <MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" 
                            HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" 
                            BorderWidth="1px" AutoGenerateColumns="False">  
                            <RowIndicatorColumn> 
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn> 
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                            <ItemStyle BackColor="LightGray" /> 
                            <HeaderStyle BackColor="#1C5E55" /> 
                            <CommandItemStyle Font-Names="tahoma" Font-Size="10pt" /> 
                            <Columns> 
                                <telerik:GridHyperLinkColumn DataNavigateUrlFields="TopicProperties.TopicId" UniqueName="TopicTitle" 
                                    DataNavigateUrlFormatString="~/Topic/pages/OpenTopic.aspx?TopicID={0}&view=web" HeaderText="Topic Title" 
                                    DataTextField="TopicProperties.Title" SortExpression="TopicProperties.Title" 
                                    Target="_blank">  
                                </telerik:GridHyperLinkColumn> 
                                <telerik:GridBoundColumn UniqueName="Owner" SortExpression="Owner.NameInListFormat" HeaderText="Owner" 
                                    DataField="Owner.NameInListFormat">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn UniqueName="WorkflowType" AllowSorting="true" 
                                    HeaderText="Workflow Type" DataField="WorkflowType">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn UniqueName="State" SortExpression="WorkflowStatus" HeaderText="State" 
                                    DataField="WorkflowStatus">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn UniqueName="PrimarySpecialty" SortExpression="TopicProperties.PrimarySpecialtyShortName" 
                                    HeaderText="Primary<br/>Specialty" DataField="TopicProperties.PrimarySpecialtyShortName">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridDateTimeColumn UniqueName="Started" HeaderText="Workflow Started" DataField="StartDate" 
                                    DataFormatString="{0:M/d/yyyy h:mm tt}" SortExpression="StartDate">  
                                </telerik:GridDateTimeColumn> 
                                <telerik:GridBoundColumn UniqueName="Completed" SortExpression="FinishedDate" HeaderText="Workflow Completed" 
                                    DataField="FinishedDate">  
                                </telerik:GridBoundColumn> 
                                 <telerik:GridBoundColumn UniqueName="InitialGradedDate" SortExpression="InitialGradedDate" HeaderText="Initial Graded Date" 
                                    DataField="InitialGradedDate">  
                                </telerik:GridBoundColumn> 
                                 <telerik:GridBoundColumn UniqueName="InitialGradedDateInRange" SortExpression="InitialGradedDateInRange" HeaderText="Within Date Range" 
                                    DataField="InitialGradedDateInRange">  
                                </telerik:GridBoundColumn> 
                                 <telerik:GridHyperLinkColumn DataNavigateUrlFields="TopicProperties.TopicId" UniqueName="TopicTitle" 
                                    DataNavigateUrlFormatString="~/Topic/pages/TopicTaskHistory.aspx?TopicID={0}" HeaderText="History" 
                                    Text="View" SortExpression="TopicProperties.Title" 
                                    Target="_blank">  
                                </telerik:GridHyperLinkColumn> 
                            </Columns> 
                        </MasterTableView> 
                        <CommandItemStyle Font-Names="tahoma" Font-Size="10pt"></CommandItemStyle> 
                    </telerik:RadGrid> 

This is how I bind the data to my grid

 List<TopicWorkflow> result = o as List<TopicWorkflow>;  
                rgTopics.DataSource = result;  
                rgTopics.DataBind();  
 
 
 
 
 
//some Customization in ItemdataBound event  
 
 
 
     protected void rgTopics_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            //Is it a GridDataItem  
            if (e.Item.DataItem is TopicWorkflow && e.Item is GridDataItem)  
            {  
                IReferenceListService referenceService = ServiceManager.Instance.GetService<IReferenceListService>();  
 
                TopicWorkflow findallVO = e.Item.DataItem as TopicWorkflow;  
                GridDataItem dataItem = e.Item as GridDataItem;  
 
 
                string linkLabel = null;  
 
                Dictionary<TopicReviewWorkflowVO.TopicWorkflowType, string> topicTasks = referenceService.GetTopicWorkflowTaskTypes();  
                Dictionary<TopicReviewWorkflowVO.TopicWorkflowStatus, string> workflowStatuses = referenceService.GetTopicWorkflowStatuses();  
 
                if (findallVO.WorkflowType == TopicReviewWorkflowVO.TopicWorkflowType.EDT)  
                {  
                    linkLabel = string.Format("<i>{0}</i>", topicTasks[findallVO.WorkflowType]);  
                }  
                else if (findallVO.WorkflowType == TopicReviewWorkflowVO.TopicWorkflowType.MCB)  
                {  
                    linkLabel = string.Format(  
                        "<href='{0}/topic/Lists/Topic%20Approval%20Tasks/DispForm.aspx?ID={1}' target='_utdGraphicEdit'>{2}</a>",  
                        ConfigUtil.ReadAppSetting(Constants.UTD_SITE_URL),  
                        findallVO.WorkflowId,  
                        topicTasks[findallVO.WorkflowType]  
                    );  
                }  
                else  
                {  
                    linkLabel = string.Format("<href='{0}/topic/pages/TopicReviewWorkflow.aspx?WorkflowID={1}' target='_blank'>{2}</a>",  
                        ConfigUtil.ReadAppSetting(Constants.UTD_SITE_URL),  
                        findallVO.WorkflowId,  
                        topicTasks[findallVO.WorkflowType]  
                    );  
                }  
 
                dataItem["WorkflowType"].Text = linkLabel;  
 
            }  
        }  
 
 
 
 
 
0
Pavlina
Telerik team
answered on 02 Jul 2010, 04:38 PM
Hi BV,

Note that advanced features like sorting, paging, filtering etc. are not supported with simple data-binding calling DataBind(). Please switch to advance binding with NeedDataSource event handling using the same code without the DataBind() call and let me know how it goes.

Kind regards,
Pavlina
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
BV
Top achievements
Rank 1
answered on 06 Jul 2010, 02:11 PM
Thanks for your guidance Pavlina..

Converting my list to datatable solved my issue..

Thanks
Bino
Tags
Grid
Asked by
BV
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
BV
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or