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

Sorting Not Working

3 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 27 Oct 2008, 09:05 PM
I have attempted to add basic sorting to my grid.  The grid loads fine, but when I attempt to sort a column the grid is just gray, no data.  Here's my code.

<telerik:RadGrid ID="grdRepl" runat="server" EnableEmbeddedSkins="False" GridLines="None" Skin="WebBlue" AutoGenerateColumns="False" Width="100%" Height="388px" AllowSorting="True" AllowMultiRowSelection="True">  
                                <PagerStyle FirstPageImageUrl="Images/Grid/PagingFirst.gif" LastPageImageUrl="Images/Grid/PagingLast.gif" 
                                    NextPageImageUrl="Images/Grid/PagingNext.gif" PrevPageImageUrl="Images/Grid/PagingPrev.gif" /> 
                                <MasterTableView ClientDataKeyNames="QTY" AllowNaturalSort="False" > 
                                    <CommandItemSettings AddNewRecordImageUrl="Images/Grid/AddRecord.gif" RefreshImageUrl="Images/Grid/Refresh.gif" /> 
                                    <RowIndicatorColumn FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">  
                                        <HeaderStyle Width="20px" /> 
                                    </RowIndicatorColumn> 
                                    <ExpandCollapseColumn CollapseImageUrl="SingleMinus.gif" ExpandImageUrl="SinglePlus.gif" 
                                        FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">  
                                        <HeaderStyle Width="20px" /> 
                                    </ExpandCollapseColumn> 
                                    <Columns> 
                                        <telerik:GridClientSelectColumn UniqueName="chkSelected" FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif"></telerik:GridClientSelectColumn> 
                                        <telerik:GridBoundColumn DataField="STOR_CDE" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store #" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="STORE_NAME" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column1">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="QTY" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Units" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column2">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="COST" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Cost" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column3">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="RETAIL" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Retail" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column4">  
                                        </telerik:GridBoundColumn> 
                                    </Columns> 
                                    <EditFormSettings> 
                                        <EditColumn CancelImageUrl="Cancel.gif" EditImageUrl="Edit.gif" FilterImageUrl="Images/Grid/Filter.gif" 
                                            InsertImageUrl="Update.gif" SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" 
                                            UpdateImageUrl="Update.gif">  
                                        </EditColumn> 
                                    </EditFormSettings> 
                                    <PagerStyle FirstPageImageUrl="Images/Grid/PagingFirst.gif" LastPageImageUrl="Images/Grid/PagingLast.gif" 
                                        NextPageImageUrl="Images/Grid/PagingNext.gif" PrevPageImageUrl="Images/Grid/PagingPrev.gif" /> 
                                    <GroupByExpressions> 
                                        <telerik:GridGroupByExpression> 
                                            <SelectFields> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&lt;BR/&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Units" 
                                                    FieldName="QTY" 
                                                    Aggregate="Sum" FieldAlias="QTY" FormatString="" /> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Cost" 
                                                    FieldName="COST" 
                                                    Aggregate="Sum" FieldAlias="COST" FormatString="" /> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Retail" 
                                                    FieldName="RETAIL" 
                                                    Aggregate="Sum" FieldAlias="RETAIL" FormatString="" /> 
                                            </SelectFields> 
                                            <GroupByFields> 
                                                <telerik:GridGroupByField  
                                                    FieldName="column1" FieldAlias="column1" FormatString="" HeaderText="" />                                                    
                                            </GroupByFields> 
                                        </telerik:GridGroupByExpression> 
                                    </GroupByExpressions> 
                                </MasterTableView> 
                                <ClientSettings> 
                                    <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                                    <Selecting AllowRowSelect="True" /> 
                                    <ClientEvents OnRowSelected="ReplRowSelected" OnRowDeselected="ReplRowDelected" /> 
                                </ClientSettings> 
                                <SelectedItemStyle BackColor="PaleGoldenrod" /> 
                            </telerik:RadGrid> 
    Protected Sub grdRepl_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdRepl.NeedDataSource  
 
        Select Case Master.pbOR.SelectedItem.Index  
 
            Case 0  
 
                PopulateReplenishmentGrid(False)  
 
        End Select 
 
    End Sub 
 
    Private Sub PopulateReplenishmentGrid(ByVal Process As Boolean)  
 
        Dim Dept As String = "" 
        Dim Vend As String = "" 
        Dim Cls As String = "" 
 
        Dim bll As New BARS.BLL.OrderReview(Environment.Selected)  
 
        'Determine which level of tree was selected  
        If Not Master.tvRepl.SelectedNode Is Nothing Then 
 
            If CurrentNodeRepl <> Master.tvRepl.SelectedNode.ValuePath Or Process Then 
 
                LastNodeRepl = CurrentNodeRepl  
                CurrentNodeRepl = Master.tvRepl.SelectedNode.ValuePath  
 
                If LastNodeRepl <> CurrentNodeRepl Or Process Then 
 
                    Dim dt As DataTable = bll.SelectPO(Convert.ToInt32(Master.tvRepl.SelectedNode.Text))  
 
                    If dt.Rows.Count > 0 Then 
 
                        grdRepl.DataSource = dt  
 
                        Dim Units As Integer = 0  
 
                        For Each row As DataRow In dt.Rows  
 
                            Units += Convert.ToInt32(row("QTY"))  
 
                        Next 
 
                        hfTotalUnits.Value = Units  
 
                    Else 
 
                        grdRepl.DataSource = Nothing 
 
                    End If 
 
                    'grdRepl.DataBind()  
                    grdRepl.Visible = True 
 
                    hfLastRetrieve.Value = "TREE" 
 
                End If 
 
            End If 
 
        End If 
 
    End Sub 
 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        Select Case Master.pbOR.SelectedItem.Index  
 
            Case 0  
 
                PopulateReplenishmentGrid(False)  
 
            Case 1  
 
                PopulateOrderReviewGrid()  
 
        End Select 
 
    End Sub 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 28 Oct 2008, 04:50 AM
Hi Dudeman,

You have not set the SortExpression property. Try setting it for the Grid columns  and see whether Sorting is working.

ASPX:
 <Columns>  
   <telerik:GridClientSelectColumn UniqueName="chkSelected" FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif"></telerik:GridClientSelectColumn>  
   <telerik:GridBoundColumn DataField="STOR_CDE" SortExpression="STOR_CDE"  FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store #"  
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column">   
   </telerik:GridBoundColumn>  
  <telerik:GridBoundColumn DataField="STORE_NAME" SortExpression="STORE_NAME"  FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store"  
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column1">   
  </telerik:GridBoundColumn>  
  <telerik:GridBoundColumn DataField="QTY" SortExpression="QTY"  FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Units"  
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column2">   
    </telerik:GridBoundColumn>  
  <telerik:GridBoundColumn DataField="COST" SortExpression="COST"  FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Cost"  
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column3">   
 </telerik:GridBoundColumn>  
  <telerik:GridBoundColumn DataField="RETAIL" SortExpression="RETAIL"   FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Retail"  
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column4">   
  </telerik:GridBoundColumn>  
</Columns>  


Thanks
Shinu.

0
Rob
Top achievements
Rank 1
answered on 28 Oct 2008, 01:44 PM
Shinu,

Thank you for your reply.

I have added a sort expression for the first databound column, but still get the same blank, gray grid after attempting to sort.  I have a very simple grid in a prototype project that seems to work fine without sort expressions, which leads me to believe that I have done something else wrong with this grid.  Here is the updated grid w/ a sort expression:

                           <telerik:RadGrid ID="grdRepl" runat="server" EnableEmbeddedSkins="False" GridLines="None" Skin="WebBlue" AutoGenerateColumns="False" Width="100%" Height="388px" AllowSorting="True" AllowMultiRowSelection="True">  
                                <PagerStyle FirstPageImageUrl="Images/Grid/PagingFirst.gif" LastPageImageUrl="Images/Grid/PagingLast.gif" 
                                    NextPageImageUrl="Images/Grid/PagingNext.gif" PrevPageImageUrl="Images/Grid/PagingPrev.gif" /> 
                                <MasterTableView ClientDataKeyNames="QTY" AllowNaturalSort="False" > 
                                    <CommandItemSettings AddNewRecordImageUrl="Images/Grid/AddRecord.gif" RefreshImageUrl="Images/Grid/Refresh.gif" /> 
                                    <RowIndicatorColumn FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">  
                                        <HeaderStyle Width="20px" /> 
                                    </RowIndicatorColumn> 
                                    <ExpandCollapseColumn CollapseImageUrl="SingleMinus.gif" ExpandImageUrl="SinglePlus.gif" 
                                        FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">  
                                        <HeaderStyle Width="20px" /> 
                                    </ExpandCollapseColumn> 
                                    <Columns> 
                                        <telerik:GridClientSelectColumn UniqueName="chkSelected" FilterImageUrl="Filter.gif" SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif"></telerik:GridClientSelectColumn> 
                                        <telerik:GridBoundColumn DataField="STOR_CDE" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store #" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="STORE_NAME" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Store" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column1">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="QTY" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Units" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column2">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="COST" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Cost" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column3">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="RETAIL" FilterImageUrl="Images/Grid/Filter.gif" HeaderText="Retail" 
                                            SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" UniqueName="column4">  
                                        </telerik:GridBoundColumn> 
                                    </Columns> 
                                    <EditFormSettings> 
                                        <EditColumn CancelImageUrl="Cancel.gif" EditImageUrl="Edit.gif" FilterImageUrl="Images/Grid/Filter.gif" 
                                            InsertImageUrl="Update.gif" SortAscImageUrl="Images/Grid/SortAsc.gif" SortDescImageUrl="Images/Grid/SortDesc.gif" 
                                            UpdateImageUrl="Update.gif">  
                                        </EditColumn> 
                                    </EditFormSettings> 
                                    <PagerStyle FirstPageImageUrl="Images/Grid/PagingFirst.gif" LastPageImageUrl="Images/Grid/PagingLast.gif" 
                                        NextPageImageUrl="Images/Grid/PagingNext.gif" PrevPageImageUrl="Images/Grid/PagingPrev.gif" /> 
                                    <GroupByExpressions> 
                                        <telerik:GridGroupByExpression> 
                                            <SelectFields> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&lt;BR/&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Units" 
                                                    FieldName="QTY" 
                                                    Aggregate="Sum" FieldAlias="QTY" FormatString="" /> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Cost" 
                                                    FieldName="COST" 
                                                    Aggregate="Sum" FieldAlias="COST" FormatString="" /> 
                                                <telerik:GridGroupByField  
                                                    HeaderText="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Retail" 
                                                    FieldName="RETAIL" 
                                                    Aggregate="Sum" FieldAlias="RETAIL" FormatString="" /> 
                                            </SelectFields> 
                                            <GroupByFields> 
                                                <telerik:GridGroupByField  
                                                    FieldName="column1" FieldAlias="column1" FormatString="" HeaderText="" />                                                    
                                            </GroupByFields> 
                                        </telerik:GridGroupByExpression> 
                                    </GroupByExpressions> 
                                    <SortExpressions> 
                                        <telerik:GridSortExpression FieldName="STOR_CDE" SortOrder="Ascending" /> 
                                    </SortExpressions> 
                                </MasterTableView> 
                                <ClientSettings> 
                                    <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                                    <Selecting AllowRowSelect="True" /> 
                                    <ClientEvents OnRowSelected="ReplRowSelected" OnRowDeselected="ReplRowDelected" /> 
                                </ClientSettings> 
                                <SelectedItemStyle BackColor="PaleGoldenrod" /> 
                            </telerik:RadGrid> 
0
Shinu
Top achievements
Rank 1
answered on 29 Oct 2008, 07:49 AM
Hi Dudeman,

In your aspx you have not set the NeedDataSource event handler. I am not sure whether you have set the event handler in the code behind. Automatic sorting will work only with AdvanceDataBinding techniques.

Shinu
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Share this question
or