Jqgrid custom format use bracket() if negatif value(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
属性在带有负数的单元格中添加 class
或 style
属性:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Jqgrid 自定义格式使用括号() if negatif value


- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01