jqgrid自定义格式如果使用negatif值,请使用方括号() [英] Jqgrid custom format use bracket() if negatif value

查看:125
本文介绍了jqgrid自定义格式如果使用negatif值,请使用方括号()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果存在负数,请在 Jqgrid 中使用任何解决方案,然后显示方括号"()"吗?

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

ex:如果值是-23,则显示(23)

ex: show (23) if value was -23

谢谢

推荐答案

您可以使用自定义格式化程序执行所需的操作.要正确格式化数字或整数,可以使用$.jgrid.formatter.number$.jgrid.formatter.integer作为第二个参数来调用$.fmatter.util.NumberFormat方法.模仿者的例子是

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 + ')') + ' €';
}

您还可以更改颜色或其他显示负数的CSS样式.您可以使用cellattr属性在具有负数的单元格中添加classstyle属性:

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

这篇关于jqgrid自定义格式如果使用negatif值,请使用方括号()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆