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 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01