Using CSV to fill DataTable
Using CSV to fill DataTable
epschroeder
Posts: 5Questions: 0Answers: 0
Hello all,
I have searched the forum but have not found an answer yet so I hope someone can help me.
I want to use a csv file to fill my DataTable. I have read that I have to convert it to JSON but have not found out how.
I have no experience with JSON so please help me out!
I have searched the forum but have not found an answer yet so I hope someone can help me.
I want to use a csv file to fill my DataTable. I have read that I have to convert it to JSON but have not found out how.
I have no experience with JSON so please help me out!
This discussion has been closed.
Replies
I'd be a little surprised if you couldn't find something out there on the internet that does this. I found a site that will convert csv to an HTML table - I was planning on using this in my app: http://area23.brightbyte.de/csv2wp.php there were several others, but this was the best that I had seen, and is downloadable to run on your own site.
Just a google search away are tools to convert csv to json: http://www.zenovations.com/misc/convertcsv/
thank you for your reply.
I did find the tools on the internet but they are not what I'm looking for.
What I want DataTables to do is convert csv to JSON on the fly.
The client I am writing this webapp for can only upload .csv files from their software automatically so a conversion tool won't be a solution.
Hope you or someone else can still help me out.
But I can;t find a good example code without uploading a file. I want it to happen on the fly and my coding skills don't go that far.
Can anyone help me out with the code needed to convert a csv to json and load it in a datatable?
Much appreciated!
I succeeded in getting JSON from my csv file inside a variable. What I still need to do is use this variable (called jsonText) to fill my datatable. Can someone help me this?
http://www.egbertschroeder.com/alert_jsonText.jpg
DataTables expects it to have an aaData key. At minimum it requires something like the following:
[code]
{ "aaData": [
["Trident","Internet Explorer 4.0","Win 95+","4","X"],
["Trident","Internet Explorer 5.0","Win 95+","5","C"],
["Other browsers","All others","-","-","U"]
] }
[/code]
(yoinked from DT example pages)
There's flexibility in how the JSON is nested, but I'm fairly confident that after conversion it needs to at least be framed in the {"aaData": [ ] } pattern.