How to solve long string(numeric) issue in datagrid?
- What I am trying to do:
I am trying to build simcard management dashboard.
- What I did:
so for this, I created table grid and displayed simcard data such as card number, phone number etc from external api.
- My issue:
For example, simcard number format is 9999999999999999999, but it's showing like 1.0E+20
I verified simcard number was loaded correctly from external api, but showing wrong on table grid, so I tried to use formatStateUsing function, but still showing wrong.
I can't solve this problem.
- Code:
50 Replies
I hope someone help me please
PHP: Hypertext Preprocessor
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
I know this function, but I don't want to add any decimals or commas because its simcard number
Hi @undercode
Do you know how?
Wow
I see, I will try now.
Okay I tried.
The correct simcard number from external api is 89450136240822000001
Now, datagrid is showing like this.
Correct one
Well, filament table can't handle large int value?
bigint value?
Maybe you have to store it as string, not int
Of course
I am able to get simcard number as string from external api
When I log simcard number, I can see 9999999999999999999 for example correctly.
But the problem is only when displaying this on datagrid.
I don't understand why filament can't handle this and why filament detects this kind of string as numeric.
I think, this is a very critical problem and issue in filament library
Do I need to report this issue to filament dev team?
I'm going to replicate your issue...
Sounds good thank you so much!
Is your field defined like:
$table->string('imei')
?Well, I don't use laravel database such as mysql etc.
ok
I see
I load data from baserow
api
But hold on
In baserow, yes IMEI filed is string field.
Not numeric field
As I mentioned above, the problem is filament detects long string(not text) as number, so it shows like 1.0E+20 etc I guess.
It seems more a php precision thing than a filament one, because number displayed is different when using ini_set('precision', 20)
Maybe GNU Multiple Precision could help you. https://www.php.net/manual/en/book.gmp.php
PHP: Hypertext Preprocessor
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
Great!
Thank you
Did you replicate my issue?
Yes, i did. And with ini_set('precision', 20) the IMEI is displayed as
Yeah, then, it shows wrong
Then, not sure how to solve this.
This is very big critical problem.
Could you share how you load your json and how you parse it?
Sure
I will share php file, okay?
ok
app/Filament/Resources/SimcardResource.php
And json response format is...
But in table() function in SimcardResource.php file, IMEI value shows 1.0E+20
public static function table(Table $table)
Simcard.php model works with baserow api. Not database.
Ok, but you are using Sushi, with uses SQLite to store your data. Try to add this line to your Simcard model:
Ok, let me try. 👍
Then, I don't need part?
->formatStateUsing(fn ($state) => number_format(floatval($state), 0, '', ''))
No
Ok, it's showing 89450136240821993472
But it should be like . 89450136240822000001
😖 . Not sure why.
I added copyable to this field, so when I copied, it's like this.
8.9450136240822E+19
Ok, remove $casts and add this line:
Ok thank you.
Same issue.
If you want , you can check directly in my computer via anydesk.
Let me think how to solve this problem.
I think, this is filament table library issue.
No, it's not. It's Sushi's
Do you have a sqlite database in your database folder?
But as you can see json, I am able to load simcard data correctly.
Try to remove it
Let me check
There is no sqlite file in database folder.
This is Sushi function to create the table and its fields:
As you can see, the function creates field types based on the contents of the field.
I installed Sushi package, but I didn't create any sqlite database file manually, or even I don't know where is sqlite database file.
Yeah, I see
So, when loading data, Sushi tries to insert data first before showing data to table, yes?
Exactly. And creates a new table if not exsists.
I checked createTable function of Sushi, so oh, there is is_int, is_numberic cases.
So, Sushi detects simcard number as numeric
Not as string.
Hmmm
Exactly! You can specify field types in your
$schema
variable: https://github.com/calebporzio/sushi?tab=readme-ov-file#custom-schemaGitHub
GitHub - calebporzio/sushi: Eloquent's missing "array" driver.
Eloquent's missing "array" driver. Contribute to calebporzio/sushi development by creating an account on GitHub.
Awesome!
I will try.
Well, we tried this already, but didn't work.
protected $schema = [
'IMEI' => 'string',
];
But let me think again.
Try
php artisan cache:clear
Ok
Not working.
Actually, I tried to clear cache already.
I can't think of anything else, sorry.
Try to make a repo in github and I'll try when I have time
Yup, I understand.
Thank you so much! for your help and ideas.
Oh nice!
After adding this part into model ,
And removed this part,
I can see correct simcard number.
Of course, I ran command, so I can see correctly.
Thank you for your help!
👍👍👍
So my problem is solved.
@undercode
Can you please help me on this ?
https://discord.com/channels/883083792112300104/1321818842401603636