Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

php - Jqgrid custom format use bracket() if negatif value

Is any solution in Jqgrid if there is negative number then show bracket "()" ?

ex: show (23) if value was -23

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use custom formatter to do what you want. To format numbers or integers correctly you can call $.fmatter.util.NumberFormat method with $.jgrid.formatter.number or $.jgrid.formatter.integer as the second parameter. The example of the formetter is

formatter: function (cellvalue, options) {
    var value = parseFloat(cellvalue), retult,
        op = $.extend({}, $.jgrid.formatter.number); // or $.jgrid.formatter.integer

    if(!$.fmatter.isUndefined(options.colModel.formatoptions)) {
        op = $.extend({}, op,options.colModel.formatoptions);
    }
    retult = $.fmatter.util.NumberFormat(Math.abs(value), op);
    return (value >= 0 ? retult : '(' + retult + ')') + ' €';
}

you can additionally change color or some other CSS style of displaying of the negative numbers. You can use cellattr property to add class or style attribute in the cells with negative numbers:

cellattr: function (rowid, cellvalue) {
    return parseFloat(cellvalue) >= 0 ? '' : ' style="color:red;font-weight:bold;"'
}

The demo demonstrate the settings. The results are the following

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...