hi
I want to export CSV file data into ionic-selectable
any help?
@layaln what are you using: angular, react, vuejs, vanillajs? and have you tried something at this point?
Iām using angular
yes I have tried papa parser
I exported data but I had a problem to use specific columns from the file
@layaln Sorry did not saw your reply before. Ok understand, just to be sure you want to get the data from a csv file and put it into a ionic-selectable ( the library ) or an element?
I used a simple line splitter
try {
csvData.match(/[^\r\n]+/g).map((line: string) => {
const columns = line.split('|');
```
The try in order to avoid runtime issues.
thatās right
thatās what i want
Iāll try that thank you
Iām not sure what sort of guarantees you have over your input, but in a normal situation, I would never do that, because in the past I have tended to run into situations where that delimiter needs to be included in data: i.e. āwhat happens when one of my fields has a ā|ā in it?ā. split
is really primitive.
This is also why I am not very fond of CSV as an input format. Export, fine. I donāt mind writing it, but I donāt like to read it without a dedicated and high-quality parser. Thereās also nothing that CSV can do that JSON canāt do better, and plenty of things JSON can do that are downright gnarly in CSV, such as variable-length records.
True
I have full control over the input in my case
There is indeed so much more to say about csv that indeed u wonder why try do make it yourself
This is just complete speculation on my part, but I blame spreadsheets. More accurately, I blame people for whom spreadsheets are their hammer, rendering all the world a rigid grid of nails. People start out prototyping things in a spreadsheet, and then once they hit a wall, the first thing they demand in the next-generation system is the ability to import all the cruft from the spreadsheet.
For all the hate that I heap upon JavaScript daily, JSON is brilliant. Itās almost as easy to read for humans as YAML, and way easier to parse. If youāre writing web apps, you already have first-order JSON support in your frontend, and any sane backend stack I have ever heard of has at least decent support for it. I often lean on PostgreSQLās jsonb
datatype to implement arbitrary ādetailsā or āextrasā bags in database design in order to allow adding new relatively unimportant bits of data to records without necessitating modification to the database schema (or usually even to the application server, which simply passes these things through as opaquue JSON without concern for their contents).
So what Iām primarily trying to say here is I think that JSON should always be the default transfer format for anything youāre processing in an Ionic app. Itās generally much easier to massage whatever one has into JSON on the backend than it is to futz about with non-JSON in the frontend.
True enough. My justification is lack of priority in developing a grid (or other) type of way in the frontend for adding rather static data regurlarly (list of 100 entities) every 6-9 months (which dont change often )
And the admin end user (1) gets an excel template to gather the data properly.