Results 1 to 2 of 2

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

  1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Location
    Freiburg
    Posts
    24
    Answers
    1
    Vote Rating
    2
      0  

    Question 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,790
    Answers
    583
    Vote Rating
    390
      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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •