Leading zero problem
Leading zero problem
Hello!
I have in database column (type varchar), where I store four digits.
When I display them using Datatables there ore two options:
- if the first digit is not a zero, no problems
- if the first digit is zero, datatables do not display the leading zero.
In case I update this field via datatables and in my update request I include the leading zero, it is correcty updated in database with leading zero, but never displayed in Datatables.
To generate data I use this:
Field::inst( 'publish_data.passport_number' ),
Field::inst( 'publish_data.passport_issue_date' )
To render data I use this:
{ data: null, render: function ( data, type, row ) {
return data.publish_data.passport_series+' '+data.publish_data.passport_number;
}
},
I have already spent two days reading similar cases, but was not able to find a solution, sorry about that.
This question has an accepted answers - jump to answer
Answers
Why is it a varchar field if it's always four digits?
And if you never want to display leading zeros, why not have the database return the required format?
It's definitely worth considering tangerine's comments and consider changing the database schema.
You would need to do that check in
columns.render
, and remove it there.If still no joy, could you update this test case to demonstrate the issue, please.
Colin
Thanks a lot for reply!
tangerine, the problem is that for digits are not digits, but a string (they are part of passport number and it is important to keep the leading zero. For example 0123 is not the same as 123 from passport number point of view).
colin, the task is not to remove the leading zero, but to show the string "as is", without removing zeroes
Oh, okay.
I don't know why DataTables would not be representing your string correctly. I suggest you provide a test case so we see your code running.
https://datatables.net/manual/tech-notes/10
My case is similar to this example:
https://editor.datatables.net/examples/simple/fieldDefaults.html
How is possible to save 0123 and, then, to represen it in column Ext of this example?
I just looked at the example, and did a couple of edits, and I don't get why it won't display leading zeroes.
Also, the "New" button isn't working.
We need one of the development team in here.
Yep, it's on Allan's list, so he'll be replying at some point today.
Colin
It is being caused by this change. Basically when
JSON_NUMERIC_CHECK
is used, it will return any numeric strings as an actual JSON number - which can sometimes be desirable (1, 2).But not in all cases!
The immediate solution is to use:
I think we should probably remove that option from the default code since it was only added recently. We'll make it optional. That will be done for 1.9.6.
Allan
hi @tangerine
for add button, perhaps in sample use of def value for extn ...
Thank you, Allan!
Fix committed here. As I say, it will be in 1.9.6.
The new way to pass
json_encode
options is a second optional parameter for theEditor->json()
method - e.g.:Allan
@allan is the ? best ?
Allan, thank you so much!! It works now as I need!