AW.Formats.Number for Negatives disdplayed as (100)
Alex
I have an grid that has a god awful amount on columns. Its being used to display finiancial information is the numbers are displayed as
1000 for Pos
(1000) for neg
The issue is the sort is not taking into account the (). It is treating all numbers as POS. I'm using the AW.Formats.Number. I'm just not sure how to make a format change to handle the neg numbers.
Is there something i can do to handle this.
Thank you,
Mb
Mike B
November 22,
If you are using setCellText() method to assign the grid content you should replace textToValue() method of the AW.Formats.Number object with the one which converts numbers in () into negative values. Currently this method just removes all characters except 0-9.+- before conversion.
Alex (ActiveWidgets)
November 23,
Alex
I'm still a little confused on where it changes. Is it in the actually AW.Formats.Number.create?
If so I'm not quite sure where or how. I've been trying I'm just worried about breaking something.
AW.Formats.Number.create=function(){
var obj=this.prototype;
obj.dataToValue=function(v){
return Number((""+v).replace(numPattern,""))
};
obj.textToValue=function(v){return Number((""+v).replace(numPattern,""))};
var numPattern=/[^0-9.\-+]+/gm;
var noFormat=function(value){
return ""+value
};
var doFormat=function(value){
var multiplier=this._multiplier;
var abs=(value<0)?-value:value;
var delta=(value<0)?-0.5:+0.5;
var rounded=(Math.round(value * multiplier)+delta)/multiplier+"";
if(abs<1000){
return rounded.replace(this.p1,this.r1)
}
if(abs<1000000){
return rounded.replace(this.p2,this.r2)
}
if(abs<1000000000){
return rounded.replace(this.p3,this.r3)
}
return rounded.replace(this.p4,this.r4)
};
obj.setTextFormat=function(format){
var pattern=/^([^0#]*)([0#]*)([ .,]?)([0#]|[0#]{3})([.,])([0#]*)([^0#]*)$/;
var f=format.match(pattern);
if(!f){
this.valueToText=function(value){
return ""+value
};
this.dataToText=function(value){
return ""+value
};
return
}
this.valueToText=doFormat;
this.dataToText=function(v){
return doFormat.call(this,Number((""+v).replace(numPattern,"")))
};
var rs=f[1];
var rg=f[3];
var rd=f[5];
var re=f[7];
var decimals=f[6].length;
this._multiplier=Math.pow(10,decimals);
var ps="^(-?\\d+)",pm="(\\d{3})",pe="\\.(\\d{"+decimals+"})\\d$";
this.p1=new RegExp(ps+pe);
this.p2=new RegExp(ps+pm+pe);
this.p3=new RegExp(ps+pm+pm+pe);
this.p4=new RegExp(ps+pm+pm+pm+pe);
this.r1=rs+"$1"+rd+"$2"+re;
this.r2=rs+"$1"+rg+"$2"+rd+"$3"+re;
this.r3=rs+"$1"+rg+"$2"+rg+"$3"+rd+"$4"+re;
this.r4=rs+"$1"+rg+"$2"+rg+"$3"+rg+"$4"+rd+"$5"+re};
obj.setTextFormat("")
};
Mb
Mike B
November 23,
yes, the code is this one -
obj.textToValue=function(v){return Number((""+v).replace(numPattern,""))};
var numPattern=/[^0-9.\-+]+/gm;
You can also replace the method on the single object instance -
var num = new AW.Formats.Number;
num.textToValue = function(text){return ...};
Alex (ActiveWidgets)
November 23,
Alex...
I just realized in the code that we are using an XmlTable for teh data source rather then an array.
// provide external model as a grid data source
objDetailGrid.setCellModel(table);
Is there something we can do to make it work with this approach or do I need to convert to an array first inorder to have it work.
Mb
Mike B
November 23,
Alex...
I did get it to work with converting the XML to Array but for me this is not the optimal solution.
obj.textToValue=function(v
if(v.length>1){
v = v.replace("(","-").replace(")","");
}
return Number((""+v).replace(numPattern,""))
};
Is there something in the AW Number Format for XML also?
Mb
Mike B
November 23,
With XML datasource dataToText() method of the format object is used to produce the cell text (html) and dataToValue() to get sortable (numeric) values.
By default dataToText() is implemented as a sequence of dataToValue() and valueToText() calls where valueToText() formats the value according to the specified pattern. However when the data comes already pre-formatted for display you can make dataToText() method which just returns the data without changes and dataToValue() method which returns the numeric value for sorting.
Alex (ActiveWidgets)
November 23,