How import table from file and rewrite or ignore existed
How import table from file and rewrite or ignore existed
![klymov.inekon](https://secure.gravatar.com/avatar/6b1121fb7f6d05822204bba788323b74/?default=https%3A%2F%2Fvanillicon.com%2F6b1121fb7f6d05822204bba788323b74_200.png&rating=g&size=120)
Hello. I create an import from csv and xls file like as editor example. It work fine. But I've met a problem that if I try to upload file with existed primary key - editor give an error. So I create a buttons on dialog "rewrite" and "ignore" repeatable.
I've try to change logic on frontend from editor.create(csv.length, false)
to editor.edit(csv.length, false)
but it work only with one row.
Button "action" logic can't access upload data to check if values already exist. Anyway it would be better make logic from backend to ignore or update existed data.
how I need to write logic for editor?
Replies
Sorry, I tried to understand you question, but failed to do so. I even used deepl.com and translated your text into a different language - unsuccessfully so ... The result was incomprehensible as well.
Suggestion: Would you mind writing your problem analysis in your own language and then use e.g. deepl.com to translate it into English, please. Could be helpful![:smile: :smile:](https://datatables.net/forums/resources/emoji/smile.png)
Thank you for your understanding!
If I've understood correctly, you want to check a primary key value to see if it exists in the current DataTable. If it does, update the corresponding row, if not, create a new row. Is that right?
If so, take a look at this thread and in particular the reply by Colin who was working on this for a client back then.
Allan
Partially yes. I want a window to pop up when importing where I can choose to ignore the repeated lines or change them. But I think this will be enough for me to understand how to find data in an existing table. Thanks. And sorry for my language)
No worries. Its a complex topic. Hopefully that example will help. Let us know how you get on.
Allan
I already at end (thanks thread you have send). but I've met a new problem. first time I call multiset when fill field values for editing
and then call multiset when fill field values for creating
In this case field values not empty before filling values for creating and at backend I have an error that I try to add when it already exist. So my question is - How to clear field value (or multivalue)?
You can clear the multi value by simply calling
field().val()
- e.g.field.val('');
in this case.Allan
I have an error "Cannot read properties of undefined (reading 'INSERTED')" Inserted is one column in table
My mistake. I've found that parsing datetime was wrong. I fix that. But I've met another problem with Datetime. I've send 2 rows of data. When I use multiset - it worked. But when I send data to backend js going throw getFormatter twice with one value. It working only for datetime, other columns are fine.
Maybe some problem in field option?
And watch in browser of datetime field property "s"
![](https://datatables.net/forums/uploads/editor/g7/llbt43mioujp.png)
Maybe error because field.s.multiValue is false? But I've set values by multivalue
Finally I've got solution.
The problem with the Datetime type was that during normal editing I went through getFormatter, where I parsed the time from display format (“dd.MM.yyyy HH:mm:ss”) to iso8601. But with multiset the value first went through setFormatter from iso8601 to display, but the csv datetime format was display format, just like when exporting.
my datetime field configuration
Glad you got it sorted![:smile: :smile:](https://datatables.net/forums/resources/emoji/smile.png)
Yes, nice one getting it all working as you need![:) :)](https://datatables.net/forums/resources/emoji/smile.png)
Allan