[CLOSED] globalisation of the sort function

Page 2 of 2 FirstFirst 12
  1. #11
    Below is how I intend to use the sortFunctionHandler. The sortType cannot be used here as it accepts only one parameter.
    
    Ext.net.Store.override({
        applySort: function () {
            if (this.sortInfo && !this.remoteSort) {
                var s = this.sortInfo, f = s.field;
                var st = this.fields.get(f).sortType;
                var fn = this.fields.get(f).sortFunction || function (r1, r2) 
                {
                     var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
                     return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
                   
                };
                this.data.sort(s.direction, fn);
                if (this.snapshot && this.snapshot != this.data) {
                    this.snapshot.sort(s.direction, fn);
                }
            }
        }
    });
    
    function MySortFunction(v1, v2) {
        var st1 = v1.data['name'], st2 = v2.data['name'];
        return (st1.localeCompare(st2));
    }
    What I want to achieve is similar to what is done here
    http://www.sencha.com/forum/showthre...endent-sorting.


    So I need to make modification to the source code and recompile to be able to extend the recordfield class . Is that what you are saying? your example was not clear to me.

    Regards
  2. #12
    No, you don't need to rebuild the sources.

    Please see the example how to extend RecordField as you need.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <%@ Import Namespace="System.ComponentModel" %>
    <%@ Import Namespace="System.Xml.Serialization" %>
    <%@ Import Namespace="Newtonsoft.Json" %>
    
    <script runat="server">
        class MyRecordField : RecordField
        {
            private JFunction sortFunction;
    
            [ConfigOption(JsonMode.Raw)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [TypeConverter(typeof(ExpandableObjectConverter))]
            public virtual JFunction SortFunction
            {
                get
                {
                    if (this.sortFunction == null)
                    {
                        this.sortFunction = new JFunction();
                    }
    
                    return this.sortFunction;
                }
            }
    
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [XmlIgnore]
            [JsonIgnore]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
                    ConfigOptionsCollection list = base.ConfigOptions;
    
                    list.Add("sortFunction", new ConfigOption("sortFunction", new SerializationOptions(JsonMode.Raw), null, this.SortFunction));
    
                    return list;
                }
            }
            
            
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            MyRecordField myRecordField = new MyRecordField();
            myRecordField.Name = "test";
            myRecordField.SortFunction.Handler = "alert('SortFunction')";
            this.Store1.Reader[0].Fields.Add(myRecordField);
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[] 
                { 
                    new object[] { "test1" },
                    new object[] { "test2" },
                    new object[] { "test3" }
                };
                this.Store1.DataBind();
            }
            
            
        }
    </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" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test" DataIndex="test" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jul 27, 2011 at 3:47 PM.
  3. #13
    Hi,

    Instead of adding the recordfield on page load is it possible to have it declaratively on the page as shown below. We do not want to have page_load on our MVC view pages. the code sample below will meet the meed of our project.
    <ext:Store ID="Store1" runat="server">  
            <Reader>                   
                <ext:ArrayReader> 
                   <Fields>                           
                        <ext:MyRecordField Name="test1"  sortFuntion="MySortFunction"/>  
                       <ext:MyRecordField Name="test2" Type="String"/>                    
                       <ext:MyRecordField Name="test3" />          
                   </Fields>                   
               </ext:ArrayReader>   
           </Reader>    
           </ext:Store>
  4. #14
    Sure, you can move MyRecordField class into a separate .cs file and attach it to a page like you attach Ext.Net controls:
    <%@ Register Assembly="Work" Namespace="Work" TagPrefix="myExt" %>
    Example MyRecordField.cs
    using Ext.Net;
    using System.Web.UI;
    using System.ComponentModel;
    using Newtonsoft.Json;
    using System.Xml.Serialization;
    
    namespace Work
    {
        public class MyRecordField : RecordField
        {
            private JFunction sortFunction;
    
            [ConfigOption(JsonMode.Raw)]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [TypeConverter(typeof(ExpandableObjectConverter))]
            public virtual JFunction SortFunction
            {
                get
                {
                    if (this.sortFunction == null)
                    {
                        this.sortFunction = new JFunction();
                    }
    
                    return this.sortFunction;
                }
            }
    
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            [XmlIgnore]
            [JsonIgnore]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
                    ConfigOptionsCollection list = base.ConfigOptions;
    
                    list.Add("sortFunction", new ConfigOption("sortFunction", new SerializationOptions(JsonMode.Raw), null, this.SortFunction));
    
                    return list;
                }
            }
        }
    }
    Example Usage

    <ext:ArrayReader>
        <Fields>
            <myExt:MyRecordField Name="test">
                <SortFunction Handler="alert('SortFunction');" />
            </myExt:MyRecordField>
        </Fields>
    </ext:ArrayReader>
Page 2 of 2 FirstFirst 12

Similar Threads

  1. [CLOSED] Sort in Panel?
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 06, 2012, 9:44 AM
  2. [CLOSED] combo sort
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 16
    Last Post: Jan 12, 2012, 7:29 PM
  3. Replies: 4
    Last Post: Jul 25, 2011, 4:57 PM
  4. [CLOSED] GridPanel and Sort
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 17, 2010, 8:12 AM
  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