GridPanel with Group may have some bugs about sort

  1. #1

    GridPanel with Group may have some bugs about sort

    GridPanel with Group may have some bugs about sort.
    I use GridPanel for display datas in database, and I need this data grouped when displayed.
    Also I used proxypage for the stroe to page the data in server.
    So there may some datas sperated to two pages which may be in the same group.
    then the bugs happend. In the pre-page one group named "test" is in the bottom of the page, and we need the "test" group in the top of the after-page, but "test" group is also in the bottom of the page. I debug the solution, and find it is not happened in linq. the data queried by linq is correct. when we set it to stroe without group, it is also display correctly. It is only uncorrect in stroe with group.
    You can see the example in next 2 pictures.
    Click image for larger version. 

Name:	01.jpg 
Views:	287 
Size:	97.5 KB 
ID:	3417
    Click image for larger version. 

Name:	02.jpg 
Views:	216 
Size:	101.1 KB 
ID:	3418
  2. #2
    Hi,

    Unfortunately, I'm not the best in Chinese and it's hard for me to see a sorting order.

    Anyways, could you provide a simple sample to reproduce the problem?

    I think a database is not required and you could use some dummy data.
  3. #3
    I can not reappear the bugs in English datas.So I give you example with Chinese datas.
    Please pay attiton for the first page's group name and the second page's group name.
    In the first page,there is only one group named "陈晓慧".
    And in the second page,there are two group named "陈晓慧" and "段芳莉". "段芳莉" is in front of "陈晓慧", But in my opinion, I thinke the correct order is "陈晓慧" in front of "段芳莉".
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserAdmin.aspx.cs" Inherits="CQU.Net.UserCenter.pages.User.UserAdmin" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var store = this.GridPanel1.GetStore();
    
            int i = 100;
            store.DataSource = getUsers();
     
            store.DataBind();
        }
    
        protected void StoreUser_Refresh(object sender, StoreRefreshDataEventArgs e)
        {
            int start = e.Start;
            if (start < 0)
                start = 0;
            int limit = e.Limit;
            if (limit < 0)
                limit = PagingToolbar1.PageSize;
            
            var query = getUsers();
            var users = query.Skip(start).Take(limit);
    
            var store = this.GridPanel1.GetStore();
            (store.Proxy[0] as PageProxy).Total = query.Count;
            
            store.DataSource = users;
            store.DataBind();
        }
    
        public List<User> getUsers()
        {
            int i = 100;
            return new List<User> 
            { 
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "陈晓慧"),
                new User(i++, "a", "段芳莉"),
                new User(i++, "a", "段芳莉"),
                new User(i++, "a", "段芳莉"),
                new User(i++, "a", "段芳莉"),
                new User(i++, "a", "段芳莉")
            };
        }
     
        public class User
        {
            public User(int userId, string LoginName, string teamName)
            {
                this.userId = userId;
                this.LoginName = LoginName;
                this.teamName = teamName;
            }
     
            public int userId { get; set; }
            public string LoginName { get; set; }
            public string teamName { get; set; }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Viewport ID="ViewPort1" runat="server">
            <Items>
                <ext:BorderLayout ID="BorderLayout1" runat="server">
                    <Center MarginsSummary="0 5 5 5">
                        <ext:Panel ID="Panel1" runat="server" Title="User" Icon="Lorry" Width="400" Layout="Fit">
                            <Items>
                                <ext:GridPanel ID="GridPanel1" runat="server" StripeRows="true"
                                    Icon="ApplicationViewColumns" TrackMouseOver="false">
                                    <Store>
                                        <ext:Store ID="StoreUser" SerializationMode="Complex" runat="server" SkipIdForNewRecords="false"
                                            RemoteSort="false" RefreshAfterSaving="None" 
                                            OnRefreshData="StoreUser_Refresh"
                                            WarningOnDirty="false" GroupField="teamName" GroupDir="ASC">
                                            <Proxy>
                                                <ext:PageProxy />                                        
                                            </Proxy>
                                            <Reader>
                                                <ext:JsonReader IDProperty="userId">
                                                    <Fields>
                                                        <ext:RecordField Name="LoginName" />
                                                        <ext:RecordField Name="teamName" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <ColumnModel ID="ColumnModel1" runat="server">
                                        <Columns>
                                            <ext:RowNumbererColumn Width="30" />
                                            <ext:Column DataIndex="teamName" Header="team">
                                            </ext:Column>
                                            <ext:Column ColumnID="LoginName" DataIndex="LoginName" Header="Name">
                                            </ext:Column>
                                        </Columns>
                                    </ColumnModel>
                                    <View>
                                        <ext:GroupingView ID="GroupingView1" runat="server" ForceFit="true" MarkDirty="false"
                                            ShowGroupName="false" EnableNoGroups="true" HideGroupedColumn="true" />
                                    </View>
                                    <LoadMask ShowMask="true" />
                                    <SaveMask ShowMask="true" />
                                    <BottomBar>
                                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" />
                                    </BottomBar>
                                </ext:GridPanel>
                            </Items>
                        </ext:Panel>
                    </Center>
                </ext:BorderLayout>
            </Items>
        </ext:Viewport>
        </form>
    </body>
    </html>
  4. #4
    Another confused thing is that when I not use PageProxy in Stroe, the order will different with use it.
  5. #5
    Why nobody reply this thread?
  6. #6
    Too busy here. Our priorities are the Premium Help forum and SVN.

    I will try to find time for that thread.
  7. #7
    Thank you for your reply,and I will join in the Premium in some time.
  8. #8
    Regarding the question.

    In the second page I see '段芳莉' as the first group and '陈晓慧' as the second one.

    I don't know Chinese, but I've just check the following thing in JavaScript:
    '段芳莉' < '陈晓慧'
    It is true. This is consistent with the group's order that I see.

    Please note that a default sorting order is ASC.

    To override it you can set up SortInfo for a Store:
    <SortInfo Field="teamName" Direction="DESC" />
  9. #9
    Thank you for your replay.
    I've just check the following thing in JavaScript:

    1 '段芳莉' < '陈晓慧'
    I believe this is the reason for this problem.

    But why JavaScript order not of C# code?

    for your advice,I have tried yet. But if I added SortInfo for a Store. other error sort whill happen, is not it?

    I have not read the source code of JavaScript, and I search some informations of sort in JavaScript.
    If you sort items by sort function in JavaScript. I advice you change it to localeCompare function which is supprot by JavaScript also.
    for example:
    
    var a=document.getElementById('s').value;
    a=a.split(',')
    
    //sort by default rule
    a.sort();
    document.getElementById('r1').value=a;
    
    //sort by locale rule
    a.sort(function(a,b){return a.localeCompare(b)});
    document.getElementById('r2').value=a;
    localeCompare is a standard in ECMAScript v3
    Last edited by easypower; Nov 16, 2011 at 11:55 AM.
  10. #10
    Quote Originally Posted by easypower View Post
    But why JavaScript order not of C# code?
    C# comparing depends on a current Culture.
    http://msdn.microsoft.com/en-us/goglobal/bb688122

    But JavaScript comparing doesn't depend on a Culture.

    There is the localeString() method in JavaScript. It says
    http://javascript.gakaa.com/string-l...re-4-0-5-.aspx
    comparing depends on a locale.

    But I'm not sure it will produce a consistent result in all browsers in all locales.

    The following example demonstrates that I'm talking about

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <%@ Import Namespace="System.Threading" %>
    <%@ Import Namespace="System.Globalization" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");   
            this.Label1.Text = "en-US: " + "段芳莉".CompareTo("陈晓慧");
            
            Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
            this.Label2.Text = "ru-RU: " + "段芳莉".CompareTo("陈晓慧");
    
            Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
            this.Label3.Text = "zh-CN: " + "段芳莉".CompareTo("陈晓慧");
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" Locale="zh-CN">
                <Listeners>
                    <DocumentReady Handler="Label4.setText('段芳莉' < '陈晓慧' ? -1 : 1);
                                            Label5.setText('段芳莉'.localeCompare('陈晓慧'));" />
                </Listeners>
            </ext:ResourceManager>
    
            <h1>C# results of "段芳莉".CompareTo("陈晓慧") in different cultures:</h1>
    
            <ext:Label ID="Label1" runat="server" />
            <br />
            <ext:Label ID="Label2" runat="server" />
            <br />
            <ext:Label ID="Label3" runat="server" />        
            <br />
    
            <h1>JavaScript result of comparing '段芳莉' < '陈晓慧' (uses in Store sorting):</h1>
    
            <ext:Label ID="Label4" runat="server" />
    
             <h1>JavaScript result of '段芳莉'.localeCompare('陈晓慧'):</h1>
    
            <ext:Label ID="Label5" runat="server" />
            
        </form>
    </body>
    </html>
    You can use remote sorting to avoid these problems.

    Quote Originally Posted by easypower View Post
    for your advice,I have tried yet. But if I added SortInfo for a Store. other error sort whill happen, is not it?
    Well, it just reverts a sorting order.

Similar Threads

  1. GridPanel bugs (with static example)
    By Z in forum 1.x Help
    Replies: 3
    Last Post: Feb 21, 2012, 3:20 PM
  2. Replies: 4
    Last Post: Jul 25, 2011, 4:57 PM
  3. Replies: 1
    Last Post: Feb 15, 2011, 5:45 PM
  4. GridPanel - Sort Issue
    By lucas in forum 1.x Help
    Replies: 1
    Last Post: Nov 29, 2010, 3:58 PM
  5. Sort with Conditional sort direction in JS- help!
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: May 05, 2009, 12:11 PM

Tags for this Thread

Posting Permissions