Menu

How to do the custom paging

Maya
2006-08-23
2013-03-22
  • Maya

    Maya - 2006-08-23

    Is is possible to do the custom paging using orm.net? if yes can anyone send me a piece of sample code.

     
    • David Parslow

      David Parslow - 2006-08-23

      It does not have custom paging (i.e. server side paging with start + page size) out of the box although it would be very easy to add that support because the infrastructure is there to be able to add that.  If you are still interested I can develop it for you.  The paging would be initialy on the get method of the DataManager (although in the future I plan on having it via "load on demand" collections).

       
      • Maya

        Maya - 2006-08-24

        I will really be thankfull if you develop it for me.

        thanks,
        Maya

         
        • David Parslow

          David Parslow - 2006-08-24

          Here are my ideas

          Starting out the the custom paging will only be on the root "table" (i.e. the entity that you are getting).  The story arround multiple children is a little more complex for an initial release

          The custom page will be done on the top level CriteriaGroup (i.e. The DataManager's QueryCriteria) and will use the following properties.
          AllowPaging
          PageIndex
          PageSize

          When you call DataManager.Get...Collection() in will return a collection with the following properties set
          IsPaged
          PageIndex
          PageSize

          In order for this to be effective we also need server side sorting.
          My current line of thought is that the top level CriteriaGroup (i.e. The DataManager's QueryCriteria) should have the following properties
          SortProperty which is a string property name
          SortDirection which OrmLib.SortDirection
          Some other the other options are to have
          SortProperty which is a PropertyDescriptor
          ListSortDirection which is a ListSortDirection
          Another option is to have SortProperty be a JoinPath for stronger type checking.

          What do you think?

           
          • David Parslow

            David Parslow - 2006-08-24

            The join path for sorting (if implement using a JoinPath) would need to be a the top/root level JoinPath.

            The PropertyDescriptor and ListSortDirection is the IBindingList style of sorting.

             
          • David Parslow

            David Parslow - 2006-08-24

            I forgot to mention that there would be a property on the root collection returned that is the page count

             
          • David Parslow

            David Parslow - 2006-08-24

            I have the code completed and a decent ammount of testing done on it (it still could use some more), I will see if I can do a release with the code in it (I have not done a source forge code release yet so we will see how that goes)

             
          • David Parslow

            David Parslow - 2006-08-25

            Here is some sample code of a working paging solution (it does not even require you to run a new code generation, just needs an updated ormlib.dll - which I have not posted yet)

            using System;
            using System.Collections;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.Web;
            using System.Web.SessionState;
            using System.Web.UI;
            using System.Web.UI.WebControls;
            using System.Web.UI.HtmlControls;
            using OrmLib;
            using MyOrmNetDatabaseBiz;

            namespace TestServerSidePaging
            {
                /// <summary>
                /// Summary description for WebForm1.
                /// </summary>
                public class WebForm1 : System.Web.UI.Page
                {
                    protected System.Web.UI.WebControls.TextBox TextBox1;
                    protected System.Web.UI.WebControls.DropDownList DropDownList1;
                    protected System.Web.UI.WebControls.DataGrid DataGrid1;
               
                    private void Page_Load(object sender, System.EventArgs e)
                    {
                        if ( !Page.IsPostBack )
                        {
                            DataManager dm = new DataManager(Config.Dsn);
                            dm.QueryCriteria.AllowPaging = true;
                            dm.QueryCriteria.PageIndex = 0;
                            dm.QueryCriteria.PageSize = DataGrid1.PageSize;

                            DataGrid1.DataSource = dm.GetContactCollection(FetchPath.Contact.ContactEmail);
                            DataGrid1.VirtualItemCount = dm.QueryCriteria.ItemCount;
                            DataGrid1.DataBind();   
                        }
                       
                    }

                    #region Web Form Designer generated code
                    override protected void OnInit(EventArgs e)
                    {
                        //
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                    }
                   
                    /// <summary>
                    /// Required method for Designer support - do not modify
                    /// the contents of this method with the code editor.
                    /// </summary>
                    private void InitializeComponent()
                    {   
                        this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
                        this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand);
                        this.Load += new System.EventHandler(this.Page_Load);

                    }
                    #endregion

                   

                    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
                    {
                        DataManager dm = new DataManager(Config.Dsn);
                        dm.QueryCriteria.AllowPaging = true;
                        dm.QueryCriteria.PageIndex = e.NewPageIndex;
                        dm.QueryCriteria.PageSize = DataGrid1.PageSize;
                       
                        dm.QueryCriteria.SortProperty = this.TextBox1.Text;
                        dm.QueryCriteria.SortDirection = this.DropDownList1.SelectedIndex == 0 ? OrmLib.SortDirection.Ascending : OrmLib.SortDirection.Descending;
                       
                        DataGrid1.DataSource = dm.GetContactCollection(FetchPath.Contact.ContactEmail);
                        DataGrid1.VirtualItemCount = dm.QueryCriteria.ItemCount;
                        DataGrid1.CurrentPageIndex = e.NewPageIndex;
                        DataGrid1.DataBind();
                    }

                    private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
                    {
                        DataManager dm = new DataManager(Config.Dsn);
                       
                        if (this.TextBox1.Text != e.SortExpression)
                        {
                            this.TextBox1.Text = e.SortExpression;
                           
                            this.DropDownList1.SelectedIndex = 0;
                        }
                        else
                        {
                            this.DropDownList1.SelectedIndex = this.DropDownList1.SelectedIndex == 0 ? 1 : 0;
                        }
                        dm.QueryCriteria.SortProperty = this.TextBox1.Text;
                        dm.QueryCriteria.AllowPaging = true;
                        dm.QueryCriteria.PageIndex = DataGrid1.CurrentPageIndex;
                        dm.QueryCriteria.PageSize = DataGrid1.PageSize;
                        DataGrid1.DataSource = dm.GetContactCollection(FetchPath.Contact.ContactEmail);
                        DataGrid1.VirtualItemCount = dm.QueryCriteria.ItemCount;
                        DataGrid1.DataBind();
                    }

                   
                }
            }

             
          • David Parslow

            David Parslow - 2006-08-25

            <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestServerSidePaging.WebForm1" %>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
            <HTML>
                <HEAD>
                    <title>WebForm1</title>
                    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
                    <meta name="CODE_LANGUAGE" Content="C#">
                    <meta name="vs_defaultClientScript" content="JavaScript">
                    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
                </HEAD>
                <body>
                    <form id="Form1" method="post" runat="server">
                        <asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True" AllowCustomPaging="True" AllowSorting="True"
                            AutoGenerateColumns="False">
                            <Columns>
                                <asp:BoundColumn DataField="ContactId" SortExpression="ContactId" HeaderText="Contact Id"></asp:BoundColumn>
                                <asp:BoundColumn DataField="FirstName" SortExpression="FirstName" HeaderText="First Name"></asp:BoundColumn>
                                <asp:BoundColumn DataField="LastName" SortExpression="LastName" HeaderText="Last Name"></asp:BoundColumn>
                            </Columns>
                            <PagerStyle Mode="NumericPages"></PagerStyle>
                        </asp:DataGrid>
                        <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
                        <asp:DropDownList id="DropDownList1" runat="server">
                            <asp:ListItem Value="Ascending">Ascending</asp:ListItem>
                            <asp:ListItem Value="Decending">Decending</asp:ListItem>
                        </asp:DropDownList>
                    </form>
                </body>
            </HTML>

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.