1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Location
    Freiburg
    Posts
    23
    Answers
    1
    Vote Rating
    1
    chrisjs is on a distinguished road

      0  

    Question Answered: Override Ext.util.Format in the ExtJS4 way?

    Answered: Override Ext.util.Format in the ExtJS4 way?


    Hello,

    in our code we use a custom formatter mentioned in this thread:
    http://www.sencha.com/forum/showthre...-usMoney/page3

    PHP Code:
    Ext.util.Format.deMoney = function(v) {
        
    = (Math.round((v-0)*100))/100;
        
    = (== Math.floor(v)) ? ".00" : ((v*10 == Math.floor(v*10)) ? "0" v);
        return (
    ' €').replace(/\./, ',');

    I did of this code using Ext.define with an override to 'Ext.util.Format':

    PHP Code:
    Ext.define('myApp.fixes.util.Format', {
        
    override'Ext.util.Format',

        
    deMoney: function(v) {
            
    = (Math.round((v-0)*100))/100;
            
    = (== Math.floor(v)) ? ".00" : ((v*10 == Math.floor(v*10)) ? "0" v);
            return (
    ' €').replace(/\./, ',');
        }
    }); 
    The code which uses the deMoney is like

    PHP Code:
        ...,
        
    rendererExt.util.Format.deMoney 
    With the new style, this is not working anymore. We had to change it to

    PHP Code:
        renderer: function (value) {
             return 
    Ext.util.Format.deMoney(value);
        } 
    Why is this change necessary?

  2. I'd guess that your override is being applied too late, so it's undefined at the point you're trying to pass it. Most likely this is because you're trying to pass it when you're defining the class rather than when you're instantiating it.

    What about if you try this?

    Code:
    renderer: 'deMoney'
    That'll defer the look-up until instantiation time.

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,492
    Answers
    526
    Vote Rating
    283
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    I'd guess that your override is being applied too late, so it's undefined at the point you're trying to pass it. Most likely this is because you're trying to pass it when you're defining the class rather than when you're instantiating it.

    What about if you try this?

    Code:
    renderer: 'deMoney'
    That'll defer the look-up until instantiation time.

Thread Participants: 1

Tags for this Thread