Main Region

Add percent to grid cell
2 answers | 326 views

AW
Nov 20, 2013 16:49 +00:00

Hi Matt,

How do I add a percent sign to grid column entries but still preserve to sorting, I would do this with Column Formatting/Html Expression = #COLUMN_NAME#% outside of FOEX, but this does't seem to work with FOEX.

Thanks

Alan

5 comments

AW
Alan W Nov 21, 2013 09:29 +00:00 

Hi Matt,

Yes thanks that works when the PCT data is in an identifiable column. The other situation I have is where one row of numbers in a report are percentages, but the preceding and proceeding rows are not. Any ideas?

Thanks Alan

MN
Matt Nolan Nov 21, 2013 09:52 +00:00 

Is it possible to add the % in the actual data within the report query?

e.g. SELECT CASE WHEN row_is_pct THEN col1||'%' ELSE to_char(col1, '999G999D00') END

AW
Alan W Nov 21, 2013 14:40 +00:00 

Yes that is what I started with , but we've also got a requirement to colour negative numbers (and percentages!) in red, which is achieved through JS in the page header. When you add % in the query, the JS doesn't recognise it as a number and the colouration fails. I'm sure there's a JS way around this, but I haven't managed t get it working yet. Any suggestions glady accepted!

MN
Matt Nolan Nov 21, 2013 21:08 +00:00 

How about you do the following to the value within the renderer (which is a string)

value = parseFloat(value.replace(/(%|,)/,''),10)

e.g. here's the test

parseFloat('999,999.014545%'.replace(/(%|,)/,''),10)

MN
Matt Nolan Nov 25, 2013 10:06 +00:00 

There is a row highlighting example on page 3005 in the documentation applciation.

The "getRowClassFn" JS function in your page header you should modify to strip the % sign using the script snippet I provided. e.g.

var getRowClassFn = function (record, rowIndex, rowparams, store) { var price = parseFloat(record.get("LIST_PRICE").replace(/(%|,)/,''),10); var cssClass; if (price < 100) { cssClass += " price-ok"; } return cssClass; }

MN
Nov 21, 2013 00:07 +00:00

You can add % within a number format mask on the column e.g. 999% or 999D00%

alt text

and here's how it will look:

alt text

0 comments

AW
Nov 25, 2013 09:39 +00:00

Hi Matt,

I didn't really understand what you meant in your latest comment. I've solved this using a DA and some Jquery.

Thanks for your help

Alan

0 comments

You must log in or sign up to post questions and answers.