Skip duplicate entries on import csv - Editor
Skip duplicate entries on import csv - Editor
Hello and Merry Christmas all,
I need a little bit of your help.
what I need is when I import a csv when a line has not changed to skip, if the same line has changes to update, if it is a new one to create a new record.
I find https://datatables.net/forums/discussion/59401/duplicate-entry-error-when-importing-with-changes but it did not work.
I have done it on database level (without the update) but I do not know the variables.
Any idea?
This question has accepted answers - jump to:
Answers
That thread you linked to would be the place to start. The code is there so it just need tailoring to your specific environment. When you say it doesn't work, could you expand on that and say what doesn't work, posting your code and any errors you're seeing,
Colin
Hello Colin,
Indeed I did some tailoring.
I post the error on the original thread.
Do you want to paste my code here or on the original thread?
I'd say post here, as slightly different issue to the other thread,
Colin
Hello collin,
My code is the below
When I run it I get the below error on firefox
Thank you
Suggests to me that there is a mismatch in the columns defined. What is on this line?
Allan
It is a div on which I load the page I need via ajax
I found the issue and I tried to import a csv file.
Well it import all the records and did not check for duplicate
If it is not easy to skip duplicates on csv import, then the other way to do it is on database level, but I will need to know the variables for the sql query
Hello all,
I fixed your code for a better check of duplicate entries.
indexof will always return -1 if the record exists in an array so I changed
to
As result I get in console "Data found" 3 times. I do not need to update the entries that already exists.
It is not working as expected. If you have a new value in csv it will not try to insert it on the table.
the results:
last one is new as you can see
Please build a test case showing what you currently have with an example CSV file that replicates the issue. This will allow us to help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
You can start with this base Editor example:
http://live.datatables.net/guwafemu/178/edit
Kevin
Hello all,
I have add my code here http://live.datatables.net/guwafemu/328/edit
On the csv I have 2 new rows but it add only the last one.
My CSV is the below
id,ideogram,pinyin,type,meaning
1329,多,duō,ΕΠΙΘ,πολύ
1330,多,duō,ΕΠΙΘ,πολύ
1331,多,duō,ΕΠΙΘ,πολύ
1332,多,duō,ΕΠΙΘ,πολύ
5,多,duō,ΕΠΙΘ,πολύ
6,多,duō,ΕΠΙΘ,πολύ
I fixed a few issues with the test case. You had some extra HTML (Datatables related) that made the test case confusing. You didn't load the PapaParse library and I removed the Editor ajax config:
Now the test case runs.
The first problem in your code is you are getting the data from column 0 which is the select checkbox column. You need to change to column 1 like this:
THe other problem is you are overwriting the
toCreate
variable being used to create the new rows. I commented out this code in theparseCSV()
function and changed to this:The
colData.push(get_CSV_ID)
statement is used to make sure duplicates in the CSV aren't added to the table.It seems to be working now:
http://live.datatables.net/guwafemu/331/edit
Kevin
Hello Kevin,
I add the fix to my code and I get to import 6 instead of 2!!!