[CLOSED] Ext .NET Override method best practice?

  1. #1

    [CLOSED] Ext .NET Override method best practice?

    Hi,

    I need to override createSortFunction method in Ext.util.Sorter.

    Dummy example:
    Ext.util.Sorter.override({
                    constructor: function () {
                        debugger;
                        alert('1,2,3...');
                    },
    
                    createSortFunction: function (sorterFn) {
                        debugger;
                        var me = this,
                    property = me.property,
                    direction = me.direction || "ASC",
                    modifier = direction.toUpperCase() == "DESC" ? -1 : 1;
    
                        alert('croak!');
                        return function (o1, o2) {
                            return modifier * sorterFn.call(me, o1, o2);
                        };
                    }
                });
    I tried calling the override in different events of the application, but can not find the event before rendering ExtJS components.

    In Ext.NET1.x, if applied in the Ext.onReady worked well.

    The idea is not having to replicate the call on all screens BeforeRender.

    Is there any way to replicate the behavior Ext.NET 2.x?

    Thanks,
    Last edited by Daniil; Jun 21, 2012 at 9:51 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The following appear to be working. The overrode constructor and createSortFunction are called for initial sorting and when I click on grid headers to sort.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" },
                };
                store.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 v2 Example</title>
    
        <script type="text/javascript">
            Ext.util.Sorter.override({
                constructor: function(config) {
                    alert("constructor");
                    var me = this;
            
                    Ext.apply(me, config);
            
                    //<debug>
                    if (me.property === undefined && me.sorterFn === undefined) {
                        Ext.Error.raise("A Sorter requires either a property or a sorter function");
                    }
                    //</debug>
            
                    me.updateSortFunction();
                },
    
                createSortFunction: function(sorterFn) {
                    alert("createSortFunction");
                    var me        = this,
                        property  = me.property,
                        direction = me.direction || "ASC",
                        modifier  = direction.toUpperCase() == "DESC" ? -1 : 1;
            
                    //create a comparison function. Takes 2 objects, returns 1 if object 1 is greater,
                    //-1 if object 2 is greater or 0 if they are equal
                    return function(o1, o2) {
                        return modifier * sorterFn.call(me, o1, o2);
                    };
                }
            });
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test1" />
                                <ext:ModelField Name="test2" />
                                <ext:ModelField Name="test3" />
                            </Fields>
                        </ext:Model>
                    </Model>
                    <Sorters>
                        <ext:DataSorter Property="test" Direction="DESC" />
                    </Sorters>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test1" DataIndex="test1" />
                    <ext:Column runat="server" Text="Test2" DataIndex="test2" />
                    <ext:Column runat="server" Text="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>

Similar Threads

  1. Replies: 2
    Last Post: Jun 06, 2012, 8:27 PM
  2. Desktop : Good practice
    By Yannis in forum 1.x Help
    Replies: 5
    Last Post: Mar 30, 2012, 10:32 AM
  3. [CLOSED] Override Button Method
    By softmachine2011 in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Mar 05, 2012, 7:45 AM
  4. Codebehind: Best practice
    By plykkegaard in forum Open Discussions
    Replies: 3
    Last Post: Jan 27, 2011, 8:41 PM
  5. [CLOSED] Questions about best practice for Column Renderers
    By anup in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 02, 2010, 7:55 AM

Posting Permissions