⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Can I have number fields with commas?



HumbleMonk
  • profile picture
  • Member

Posted 01 January 2013 - 17:02 PM

I use a lot of number fields in my application. It is hard to read large numbers at a glance without some type of indicator, e.g. compare 1345600 to 1,345,600. The grocery crud number filter prevents commas from being entered into the field.

Is there some way to allow commas to be entered in the number field but stripped before the item is saved? I've poked around but can't figure out where GroceryCrud prevents anything but numbers from being entered.

Ideally the flow would be something like this:

Read number field from database
Automatically populate with commas
Automatically adjust commas if field is edited
On save, strip commas and then submit

Alvin Lesmana
  • profile picture
  • Member

Posted 02 January 2013 - 08:12 AM

Put this on your controller

$crud->callback_column('price',array($this,'format_num'));


and add this function :

function format_num($value, $row){
return number_format($value, 0);
}

:)

HumbleMonk
  • profile picture
  • Member

Posted 03 January 2013 - 23:08 PM

Thank you for the answer.

That results in a formatted field, like I want, however it is not editable. I need this field to be editable.