Error when Importing CSV Data
Error when Importing CSV Data

Link to test case: http://jsfiddle.net/gen8zo5h/2/
Debugger code (debug.datatables.net):
Error messages shown: DataTables warning: table id=example - Requested unknown parameter 'Description' for row 5, column 1. For more information about this error, please see http://datatables.net/tn/4
Description of problem: I am trying to import a CSV file data into the dataTables but getting the above error. I looks correct after clicking the OK button couple of time. How do I stop getting that error? Also showing entry as one more that the data. I guess it counts the first (title) row as data.
Ultimately, what I want to do is to import the csv data into an existing dataTable (columns pre-defined) starting with the second row of the csv file. Is that possible with my code?
This question has an accepted answers - jump to answer
Answers
That's nice! I tried it with a CSV exported from this page - and it worked fine.
What steps do I need to do to reproduce the error?
Colin
You have this column config:
Sounds like row 5 doesn't have all of the columns which would cause the above error. You can use
defaultContent
to handle the missing data. Change"default": ""
to"defaultContent": ""
. If this doesn't help then, as Colin asked, provide the steps and CSV file needed to reproduce the error.Kevin
I did the same thing as Colin and it works. However after open and re-save that exported CSV file, without any changes, it causes the same issue as I have before.
Kevin, you suggestion of defaultConent did the trick. Thanks! Now back to the second part of the question: Showing 1 to x of x entries has one more than number of data rows. It seems to include the column title row as a data row. Anything I can do to get that corrected?
Also, I would like to import/load a file into an existing dataTable instead using the first row as the title. How do I define the dataTable in that case?
I don't see that. Using Colin's step when exporting the CSV from that example there is a title row but I don't see it in the table. You are using Papa Parse to import the CSV. Look at the docs if you want a different import behavior of the import. You have this:
The
header
option docs state this:The
columns.title
option will set the Header title. You have this:You will need to change this to whatever you want the title to be.
Kevin
If you re-save the exported CSV file and try to import/load, you will see the show entry count has 1 more than the data row, which I think it counts the title row. I tried "header": false in Papa.parse, the function stops working because of following error:
Uncaught TypeError: Cannot read property 'map' of undefined
I opened the CSV and re-saved it, making no changes, and the table still show 57 rows. What are you opening the CSV file with? Have you looked at the saved CSV file in a test editor?
Kevin
Wow. Maybe just me. I simply double clicked the exported file from Window Explorer. It opens in MS Excel. I then clicked File -> Save. It pops up a message "Some features in your workbook might be lost if you save it as CSV(Comma delimited). Do you want to keep using that format?", I just clicked Yes button. I am not sure which test editor are you referring to. I tried to open it with Notepad and resaved it, it works fine.
So it has something to do with saving it as CSV in Excel. I never know that. My users are definitely going to use Excel to edit the file before loading/importing. Is there a way in Excel that will not cause that issue?
I saved the file using Excel as a CSV and it imported as expected. You will need to investigate the differences between the two files. Use a text file or a file compare tool (your OS may have one builtin). Maybe there is something in Papa Parse that can help. Papa Parse is the source of the data for Datatables.
Kevin
Thanks for your help Kevin!
BTW, what's the best way to write this imported rows into a SQL table? The back-end. May be I can just process the CSV file directly. Any direction would be appreciated.
Editor can be used for that - it also has this import functionality - see here. Otherwise, yep, you'd need some other server-side script to do that.
Colin