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

Cannot get IList<T> to sort when paged in grid.

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jafin
Top achievements
Rank 2
Jafin asked on 24 Dec 2007, 06:02 AM
Using Q3-2007 1218 + hotfix.
I am having difficulties getting a custom object collection to sort, or more correclty to sort when paging to Page 2+.  From reading the docs this should ok since I am using the OnNeedDataSource to wire up the source and am using the supported IList binding.  According to the docs if done this way all sorting etc should be handled.

The custom collection will sort when the header is changed to either ascending or descending order correctly, but when using the paging control to move beyond page1 the dataset does not page at all.  When the datasource is a datatable the problem does not occur.

is there something I am missing?

Thanks,
Jason



using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using Telerik.Web.UI;

namespace Test
{
    public partial class Test : Page
    {
        public string _alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Handles the ItemDataBound1 event of the RadGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:Telerik.WebControls.GridItemEventArgs"/> instance containing the event data.</param>
        protected void Grid_ItemDataBound(object sender, GridItemEventArgs e)
        {
        }

        /// <summary>
        /// Handles the PageIndexChanged event of the RadGrid control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Grid_PageIndexChanged(object source, GridPageChangedEventArgs e)
        {
        }

        public List<Thing> ObjectList()
        {
            List<Thing> list = new List<Thing>();
            foreach (char c in _alphabet)
            {
                string str = c.ToString();
                list.Add(new Thing(str));
            }
            return list;
        }

        public DataTable ObjectListAsDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof (string));
            List<Thing> list = ObjectList();
            foreach (Thing t in list)
            {
                DataRow row = dt.NewRow();
                row["Name"] = t.Name;
                dt.Rows.Add(row);
            }
            return dt;
        }

        protected void Grid_NeedDataSource3(object source, GridNeedDataSourceEventArgs e)
        {
            uxGrid3.DataSource = ObjectList();
        }

        protected void Grid_NeedDataSource4(object source, GridNeedDataSourceEventArgs e)
        {
            uxGrid4.DataSource = ObjectListAsDataTable();
        }
    }

   
    public class Thing
    {
        public Thing(string name)
        {
            _name = name;
        }

        private string _name;
        public string Name
        {get
        {
            return _name;
        }
            set { _name = value;}
           
        }
    }
}



============================== aspx




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Test" %>
<%@ Import namespace="Telerik.Web.UI"%>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<html>
<head><title>Test</title></head>
<body>
<form runat="server" id="form1">
<asp:ScriptManager runat="server" ID="uxScriptManager"></asp:ScriptManager>
    <div>
    <telerik:RadAjaxManager ID="uxRadAjaxManager" runat="server">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="uxGrid3">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="uxGrid3" LoadingPanelID="uxRadAjaxLoadingPanel"/>
               </UpdatedControls>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting AjaxControlID="uxGrid4">
           <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="uxGrid4" LoadingPanelID="uxRadAjaxLoadingPanel"/>
             </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>
   <telerik:RadAjaxLoadingPanel ID="uxRadAjaxLoadingPanel" runat="server" Height="75px" Width="75px" Transparency="25">
       <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" />
   </telerik:RadAjaxLoadingPanel>

    After sorting, I Don't Work on Page 2. I am using a IList
<telerik:RadGrid EnableViewState="true" ID="uxGrid3" runat="server"
            ShowFooter="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="RadGrid"
            ShowGroupPanel="False" MasterTableView-DataKeyNames="Name" HorizontalAlign="NotSet" Skin="Telerik" OnNeedDataSource="Grid_NeedDataSource3">
            <MasterTableView
                PageSize="10" GridLines="Vertical" DataKeyNames="Name"
                CommandItemDisplay="Bottom" HorizontalAlign="NotSet" AllowFilteringByColumn="False">
              <HeaderStyle CssClass="GridHeader" ></HeaderStyle>
                <RowIndicatorColumn UniqueName="RowIndicator" Visible="False">
                    <HeaderStyle Width="10px" />
                </RowIndicatorColumn>
                <Columns>
                <telerik:GridBoundColumn DataField="Name" DataType="System.String" HeaderText="Test" SortExpression="Name" UniqueName="LocDesc"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="Name"
                        SortExpression="Name" HeaderText="Site">
                        <ItemTemplate>
                            <%# Eval("Name") %>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    </Columns>
                    </MasterTableView>
                    </telerik:RadGrid>

After sorting I work Fine, I am a datatable client.
<telerik:RadGrid EnableViewState="true" ID="uxGrid4" runat="server"
            ShowFooter="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="RadGrid"
            ShowGroupPanel="False" MasterTableView-DataKeyNames="Name" HorizontalAlign="NotSet" Skin="Telerik" OnNeedDataSource="Grid_NeedDataSource4">
            <MasterTableView
                PageSize="10" GridLines="Vertical" DataKeyNames="Name"
                CommandItemDisplay="Bottom" HorizontalAlign="NotSet" AllowFilteringByColumn="False">
              <HeaderStyle CssClass="GridHeader" ></HeaderStyle>
                <RowIndicatorColumn UniqueName="RowIndicator" Visible="False">
                    <HeaderStyle Width="10px" />
                </RowIndicatorColumn>
                <Columns>
                <telerik:GridBoundColumn DataField="Name" DataType="System.String" HeaderText="Test" SortExpression="Name" UniqueName="LocDesc"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="Name"
                        SortExpression="Name" HeaderText="Site">
                        <ItemTemplate>
                            <%# Eval("Name") %>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    </Columns>
                    </MasterTableView>
                    </telerik:RadGrid>
    </div>
</form>
</body>
</html>


3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 27 Dec 2007, 04:40 PM
Hi Jason,

Indeed, the issue exists as described. Thanks for notifying us and please, excuse us for the inconvenience caused. Your Telerik points have been updated.


Greetings,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
peter
Top achievements
Rank 1
answered on 20 Mar 2008, 10:13 AM
Hi,

I'm having the same problem. Is there a solution?

Regards, Peter
0
Ves
Telerik team
answered on 21 Mar 2008, 11:13 AM
Hi Peter,

This issue has been fixed in RadControls "Prometheus" 2007 Q3 SP1 released in January. Please, download the latest available version (Service Pack 2, released in February) and give it a try.


Sincerely,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Jafin
Top achievements
Rank 2
Answers by
Ves
Telerik team
peter
Top achievements
Rank 1
Share this question
or