Jqgrid 自定义格式使用括号() if negatif value [英] Jqgrid custom format use bracket() if negatif value

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

问题描述

Jqgrid中是否有任何解决方案,如果有负数则显示括号()"?

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

例如:如果值为 -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;"'
}

演示演示设置.结果如下

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

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