2

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

ex: show (23) if value was -23

thanks

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Arief Priyadi
  • 23
  • 1
  • 6
  • Please give some more detail about your issue. – Milap Mar 12 '12 at 07:31
  • `colNames:['Name','value'], colModel :[ {name:'NAME', index:'NAME', width:20}, {name:'VALUE', index:'VALUE', width:15,align:'right',formatter: 'number',summaryType:'sum'},` Ijust wan to display negatif number in bracket – Arief Priyadi Mar 12 '12 at 08:00

1 Answers1

5

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

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • After change format of negative number . Is there any way is there to SUM that column in jqgrid to assign in same grid footer ? Because as per your code number will convert into string. So $grid.jqGrid('getCol', 'columnname', false, 'sum') will return (nan). – Karthick Rajan Nov 15 '21 at 08:08