EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Pierre on April 12, 2016, 07:41:24 AM



Title: [SOLVED]Datagrid formatter problem
Post by: Pierre on April 12, 2016, 07:41:24 AM
Hello all
I have simple table column:

Code:
<th field="quantity" data-options="formatter:formatdecimal">Quantity</th>

formatdecimal looks like this:

Code:
Number.prototype.format = function(n, x, s, c) {
  var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
  num = this.toFixed(Math.max(0, ~~n));
  return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};

function formatdecimal(num){
  return num.format(2, 3, '.', ',');
}

and it says "Uncaught TypeError: num.format is not a function"
What is the problem?
Here is original code:
http://jsfiddle.net/hAfMM/612/
Is there any other option to format numbers like 123.456,78
(group separator point, decimal separator comma)

Thank you


Title: Re: Datagrid formatter problem
Post by: stworthy on April 12, 2016, 06:06:38 PM
You must convert to 'number' type before calling your 'format' function.
Code:
function formatdecimal(num){
  return parseInt(num).format(2, 3, '.', ',');
}


Title: Re: Datagrid formatter problem
Post by: Pierre on April 12, 2016, 10:26:08 PM
Awesome. Thank you.