How do we remove the minus sign from negative numbers?

How do we remove the minus sign from negative numbers and still support column sorting properly?

We already have negative numbers displaying in Red color and the new requirement is to remove the negative sign.

You need to create a custom exCell:
docs.dhtmlx.com/doku.php?id=dhtm … le_excells

in the setCValue() method you can control the value like it should be displayed in the grid.

Hi Sematik,

Thank you so much for the quick response and I really appreciate it. However, I couldn’t get the sorting to respect the real value after changing the display value.

For example,

  1. Open the rar file attached to this issue ticket;
  2. Open the “index.html” in Internet Explorer 9.
  3. Notice that “8.000” in Column “Coupon” and Row 1 are displaying in Red color;
  4. Click on the column “Coupon” and the red color “8.000” is being treated just like positive “8.000”.
  5. Open the “index.html” in source editor and you will see that on line 64 I have set its Real Value to “-8” with a negative sign. I expect column sorting to respect the Real Value only, but it isn’t.

Is this a real issue? I found that in another issue ticket (see below) you have said “Unfortunately in case of formatting the cell’s value sorting or filtering will work only with the formatted value but not the defined in dataset. You may create a custom sorting type that will suit your formatted data: docs.dhtmlx.com/doku.php?id=dhtm … om_sorting”

viewtopic.php?f=2&t=27651&p=87465&hilit=setCTxtValue#p87465

But, I’m not sure what kind of custom sorting type that I can create as I’m using real numerical numbers.

Many thanks.
Complete Demo exCell number format change and sorting.rar (130 KB)

Please, try to use the following custom exCell “roncl”.
It colorizes your value and cut the “-” in front. The sorting works correctly with it.

function eXcell_roncl(cell) { this.base = eXcell_ron; this.base(cell); this.getValue=function(){ return this.cell._orig_value; } this.setValue = function(val) { if (!val || val.toString()._dhx_trim() == "") val = "0"; this.cell._orig_value = val; if (val >= 0) this.cell.style.color = "green"; else{ while(val.charAt(0) === '-') val = val.substr(1); this.cell.style.color = "red"; } this.cell.innerHTML = this.grid._aplNF(val, this.cell._cellIndex); } } eXcell_roncl.prototype = new eXcell_edn;

sematik,

Thank you so much for the response and I really appreciate it. Your latest solution approach posted works perfectly for me.

One last thing, can we optionally display negative numbers in the format of (123,456.00) with parenthesis around it and at the same time highlight it in red color?

I tried setNumberFormat but it applies to both negative and positive numbers, which is NOT desired.

Many thanks

SetNumberformat will be applied to all the numbers in the column.
The only way is to format your value manually in your exCell function and don’t use the edn/ron formatting.