Csv files in ionic 3

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?

1 Like

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.
1 Like

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.

1 Like

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.

1 Like

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.