Non comma Separated CSV Import
I'm having issues with CSV imports, when the csv data is separated by semicolons. The columns are not recognised correctly. When i save the CSV with comma separators it works perfectly fine.
Can I somehow change the separator settings in Import?
16 Replies
Still searching for a solution
Have you tried casting the data before passing it to rules?
I did. My issue is that the importer don't even recognizes the headers. It shows all of them in a list with semicolons.
I don't think Filament currently has any interface for passing the delimiter.
https://csv.thephpleague.com/9.0/connections/controls/#the-delimiter-character
https://github.com/filamentphp/filament/blob/ff6e64e09bde4b79426fff2da092f540fdd8e8b9/packages/actions/src/Concerns/CanImportRecords.php#L85-L88
Csv character controls - CSV
Working with CSV can often be much more difficult than you expect, with different types of delimiters and complicated structures. This library makes it easy to read and write almost anything.
GitHub
filament/packages/actions/src/Concerns/CanImportRecords.php at ff6e...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Then it's time to create a pull request.
Excellent.
I noticed that there are 3 places in that class where it would need to be implemented, for the 3 different ways the importer gets instantiated
I failed on a dynamic solution.
I ended up overwriting the CanImportRecords trait and created my own ImportAction. Within first I changed the code on those three places by adding ->setDelimiter(';') calls.
It works for me now. Tough I dislike this solution a little bit.
Here's my proposed changes:
Here's a gist to test it with. Curious your feedback @igorclauss
https://gist.github.com/drbyte/c944c3acda2bafb364a857ac6e2c8ce6
Gist
draft: filament csv import delimiter
draft: filament csv import delimiter. GitHub Gist: instantly share code, notes, and snippets.
To use: pass
->delimiter(';')
to your importerAwesome, 👍
same as you would for maxRows or other params
That's how I fixed it for me.
But I did it in the trait itself
I thought there must be a way to guess the delimiter. Because we have the csv file...
Ya I read somewhere that it may try to guess it on its own, but I couldn't see "where" it did that.
So, figure, if someone "needs" to specify it, this will let them.
... without having to clone the entire trait and edit it 🙂
PR submitted. Feel free to add your test results in comments: https://github.com/filamentphp/filament/pull/10176
GitHub
Add ability to specify ->delimiter(char) for CSV separator by drbyt...
Ref: League CSV docs
Ref: Filament Discord discussion
Changes have been thoroughly tested to not break existing functionality.
New functionality has been documented or existing documentation has...
I haven't found the guessing either. But League csv definitely has a method for that, haven't they?
I found this solution:
It was merged right next to your solution. Great work and thanks for the inspiration.