0

I am using Kendo and i want to format a number with spaces (in my grid columns) like this example: 123456789 to 123 456 789 But i didnt find this format

is some one know it?

  • How are you configuring your grid, via jquery or HTML Helpers? – Ross Bush Oct 13 '17 at 17:42
  • this is my code: columns: [ { title: "Hello", template: "#: Especes #€", field: "Especes", format: "{0:c}" }, And i want the format with spaces – Abdessalem MANAI Oct 13 '17 at 17:45
  • How about --> template: "#=jsFunctionToPerformFormatting(Especes)#"" or are you asking is there a format function for number with spaces? – Ross Bush Oct 13 '17 at 17:54
  • i am open for the two solutions to insert spaces in my numbers – Abdessalem MANAI Oct 13 '17 at 17:58
  • how to do it with this function jsFunctionToPerformFormatting(Especes) ? – Abdessalem MANAI Oct 13 '17 at 18:00
  • according to kendo UI docs you should be able to use something like kendo.toString(number, "## #") ... as @Abdou correctly points out (without even knowing it), the Telerik team have dropped the ball on something fundamental in their framework so we are forced to handle it. – War Apr 03 '20 at 12:04

1 Answers1

1

To format the number with spaces as the thousands separator, you can use the answer from here: How to print a number with commas as thousands separators in JavaScript

Assuming no decimals:

function numberWithSpaces(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
} 

Then your column definition would be

{ 
  field: "Especes", 
  title: "Hello",
  template: function(dataItem) {
    return "<span>" + numberWithSpaces(dataItem.Especes) + "</span>"
  }
}

DEMO

ezanker
  • 24,628
  • 1
  • 20
  • 35