Column Render function - with Percent sign

Column Render function - with Percent sign

Jawa-the-HuttJawa-the-Hutt Posts: 1Questions: 0Answers: 0

I looked over the forums and SO and didn't find the exact answer to my issue. I want to automatically render a column as a percentage. I know I can bring this in as a string with the percent sign appended to it, but I need to do some math on the column for an average that will show up in the table footer.

So, is there currently a built in way to automatically render a column as a percentage?

I couldn't find one, so I customized the 'dataTable.render' function to allow for an additional option that takes in the string 'pre' or 'post' and based on that, it will apply the character wanted to the beginning or end of the number.

So for currency, it would look like this:

     render: $.fn.dataTable.render.number(',', '.', 0, 'pre', '$') 

For percentages, it would look like this:

     render: $.fn.dataTable.render.number(',', '.', 0, 'post', '%')

From my limited testing, I can't find any reasons why this isn't working as I intended. You can still sort these columns without any issues.

if you want to take a look at the code, private message me.

This discussion has been closed.