Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SimpleType + formatCellValue

    Hi Isomorphic,
    we are using SimpleTypes for formating numbers to various user-formats. In the beginning it worked great but now we encountered some problems:

    Here and there we use the function formatCellValue to add measures or little icons to numbers. If we do so, the simpletype will be ignored. Is this the indended behavior?

    For a sample we edited a part of your example-library
    (girds->appearance->format values)
    Code:
    isc.ClassFactory.defineClass("GsnumberItem", "TextItem");
    isc.GsnumberItem.addProperties( {
        mapDisplayToValue : function(displayValue) {
            var value = displayValue.toString().replace(/\./g, '');
            value = value.replace(/,/g, ".");
            if (isNaN(value))
                return displayValue;
            if (value.length <= 0)
                return null;
            return parseFloat(value);
        },
        mapValueToDisplay : function(internalValue) {
            if (internalValue == undefined || isNaN(internalValue))
                return '';
            else {
                var value = internalValue.toString().replace(/\./g, ","); 
                var exp = new RegExp('(^\,-?[0-9]+)([0-9]{3})');
                while (exp.test(value)) {
                    value = value.replace(exp, "$1.$2");
                }
                return value;
            }
        }
    });
    isc.SimpleType.create( {
        name :"gsnumber",
        inheritsFrom :"float",
        normalDisplayFormatter : function(internalValue) {
            return this.shortDisplayFormatter(internalValue);
        },
        shortDisplayFormatter : function(internalValue) {
            if (internalValue == undefined || isNaN(internalValue))
                return '';
            else {
                var value = internalValue.toString().replace(/\./g, ",");
                var exp = new RegExp('(^\,-?[0-9]+)([0-9]{3})');
                while (exp.test(value)) {
                    value = value.replace(exp, "$1.$2");
                }
                return value;
            }
        },
        editorType :"GsnumberItem"
    });
    
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
        data: countryData,
        fields:[
            {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png"},
            {name:"countryName", title:"Country"},
            {name:"independence", title:"Nationhood", type:"date",
                formatCellValue: function (value) {
                    if (value) {
                        return value.getShortMonthName()+' '+value.getDate()+', '+value.getFullYear();
                    }
                }
            },
            {name:"gdp", title:"gdp", type:"gsnumber"
              //, formatCellValue: "value + ' I am a test'"
            }
        ]
    })
    The decimal-point will be displayed as comma in the last column. If you activate the formatCellValue, the simletype will be ignored and you 'll see a decimal-dot.

    #2
    Hi GravityShock,
    Yes - this is the intended behavior - the value parameter passed to formatCellValue is the raw data value, not the formatted string that would normally be displayed.

    If you want to apply the standard type based formatter to this value, and then further manipulate it you will have to call the formatter method directly.
    We have a (currently undocumented) method SimpleType.getType which will allow you to get at your SimpleType definition - so you could do something like this:

    Code:
    formatCellValue : function (value) {
       return "XX" + isc.SimpleType.getType("gsnumber").shortDisplayFormatter(value);
    }

    Comment


      #3
      I've tested your code withhin a part of our application and it works great.

      Thanks for the fast help!

      Comment

      Working...
      X