1. #1
    Ext User
    Join Date
    Dec 2007
    Location
    italy
    Posts
    120
    Vote Rating
    0
    tarini is on a distinguished road

      0  

    Default [extending Ext.grid.ColumnModel...] dataIndex and sortIndex

    [extending Ext.grid.ColumnModel...] dataIndex and sortIndex


    I would like to share with you this little upgrade of Ext.grid.ColumnModel.

    I've added a new options for each column: sortIndex.

    This options aims to split between dataIndex (used to find property inside the related store) and storeIndex (property name used to sort data).

    In my example I've two fields encapsulate the same semantic:
    - date (a simple javascript date object)
    - dateToString (locale-rappresentation of the date - created runtime as a new field without using renderer)

    In grid I would like to show dateToString field and aims user to remotely sort this field using date property (dateToString isn't a server-side property). With this upgrade you can do this!

    Here my little code:

    Code:
    Ext.grid.ColumnModel.override({
    	getSortIndex : function(col) {
    		return this.config[col].sortIndex || this.config[col].dataIndex;
    	},
    	findColumnIndex : function(dataIndex){
            var c = this.config;
            for(var i = 0, len = c.length; i < len; i++){
                if(c[i].dataIndex == dataIndex || c[i].sortIndex == dataIndex){
                    return i;
                }
            }
            return -1;
        }
    });
    Ext.grid.GridView.override({
        onHeaderClick : function(g, index){
            if(this.headersDisabled || !this.cm.isSortable(index)){
                return;
            }
            g.stopEditing(true);
            g.store.sort(this.cm.getSortIndex(index));
        }
    });
    here usage:
    Code:
    ...., {
                                    header: "Date",
    				sortable: true,
    				dataIndex: "date",
    				sortIndex: "dateToString",
    				width: 35
    			}, ....
    have fun

  2. #2
    Touch Premium Member
    Join Date
    Jul 2009
    Posts
    23
    Vote Rating
    1
    dschano is on a distinguished road

      0  

    Default good work!

    good work!


    exactly what i was looking for.
    the only tiny issue is at the "usage code", it should be sortIndex:'date' and dataIndex:'dateToString' .

  3. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    1
    Vote Rating
    0
    JVCHBABU is on a distinguished road

      0  

    Default


    It works fine, where as I am using this functionality in multiple pages and each page contains the below code fragment.


    Ext.grid.ColumnModel.override({
    getSortIndex : function(col) {
    return this.config[col].sortIndex || this.config[col].dataIndex;
    },
    findColumnIndex : function(dataIndex){
    var c = this.config;
    for(var i = 0, len = c.length; i < len; i++){
    if(c[i].dataIndex == dataIndex || c[i].sortIndex == dataIndex){
    return i;
    }
    }
    return -1;
    }
    });
    Ext.grid.GridView.override({
    onHeaderClick : function(g, index){
    if(this.headersDisabled || !this.cm.isSortable(index)){
    return;
    }
    g.stopEditing(true);
    g.store.sort(this.cm.getSortIndex(index));
    }
    });

    Is there any better way to put it in a common file and calling it using function call?

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar