0

ALL, I'm trying to create a custom formatter using jqgrid which should be feasible to set the precision and scale values.

Most of the forum questions are mentioning only about the decimal places but I would like to RESTRICT the digits before and after the decimal places.

i.e, the cell should have 2 digits before decimal places and 2 digits after decimal places. When user types 123456, then after keyOut event the cell should display 12.34

Any suggestions?

Faz
  • 534
  • 1
  • 9
  • 27
  • Sorry, but I don't understand the requirements because `123456` and `12.34` have **absolutely different values**. I could understand in displaying something like `12.34E4`, but the usage the same value `12.34` for both `123456` and `123456789` seems me not logical. Moreover you wrote at the beginning about creating **custom formatter** used for example during loading the data from the server and then wrote about absolute another scenario where **user types 123456**. Where types the user? Do you mean some external control or editing of some grid data? – Oleg Sep 30 '15 at 14:14
  • Sorry if I was not clear. Am not referring to the formatter while loading the data but was actually referring to editOptions to have the dataInit() method format the value the user types in the cell. Say for example, if the user types 123456, then the datainit function should have the number formatted as 12.34 (in which the total allowed number should be 4 - 2 before decimal points and 2 after decimal points) – Faz Sep 30 '15 at 14:26
  • In that case the decimal point should automatically be placed after 2 digits (12).. and the other digits after(34) should be truncated.. thereby allowing total of 4 digits – Faz Sep 30 '15 at 14:28

1 Answers1

1

It seems to me that you need no custom formatter used during loading of the data from the server for example. Instead of that you need to use some control in the input field of editing of the grid. For example mask plugin (see the old answer) allows to implement what you want. Additionally one can set maxlength property of input field (see the documentation) to restrict the maximal number of characters which the user can type. If the user would type 123456 then only the first 4 characters will be displayed (as 12.34) and no 5 or 6 will be see at all.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Maxlength is fine to restrict it to 4 digits as I wanted but is there a way apart from using the mask plugin to actually format the number to place decimal point after 2 characters? – Faz Sep 30 '15 at 15:04
  • @Faz: What I mean is the usage of plugin like the mask plugin first of all. Maxlength is *optional* setting which can be helpful depend on the plugin which you use. – Oleg Sep 30 '15 at 15:13