Import CSV with parent ID
Import CSV with parent ID
I have Parent - Child tables - Quiz
and Question
. With Alan's help they are working perfectly.
Now I am trying to import Questions
using this example. The import works fine except I don't know how to send the id
of the parent table [Quiz
].
I have added the following code that adds a new field to the Question
editor in the initSubmit
event. That seems to work but it is adding it to each record. Is there a better way of sending in the quizId
to the server?
questionSimpleEditor.on('initSubmit', function (e, action) {
return new Promise(function (resolve) {
var quizId22 = quizTable.row({ selected: true }).data().Id;
questionSimpleEditor.add( {
name: "quizId",
type: "hidden",
}, null);
questionSimpleEditor.val('quizId', quizId22);
questionSimpleEditor.submit();
resolve("");
});
});
This question has accepted answers - jump to:
Answers
I'd say that is close, but small modification. When you first create
questionSimpleEditor
add yourquizId
field there. Then set its value in theinitSubmit
as you are doing, but don't callsubmit()
(already in the submit phase, so no need to).Allan
Thank you allan. The reason I did not add
quizId
to thequestionSimpleEditor
is because after I upload the file, that field still shows up on the form before submission even if I mark it as hidden. Is there a way to hide that field? If so, it will be great.Also, do you now I can disable the
New
&Import CSV
buttons in the child table till user selects a row in the parent table?I never considered the case of want to upload a file with a hidden field to be honest. I don't actually quite get that - could you explain that a little further for me please?
Also you can use
button().enable()
andbutton().disable()
to enable / disable buttons. Useselect
to know when a row has been selected.Allan
Thanks for the
New
idea. Would you suggest I disable them when the child table is first loaded and enable them when a parent row is selected?As to why I need to send a value via hidden field - here is the scenario
I have a Parent table -
Quiz
. EachQuiz
has multipleQuestions
for which I have a child table.I am using the
Import CSV
to importQuestions
for a givenQuiz
. On server side, I needid
of the selectedQuiz
to save theQuestions
in the my database.Please note that I am not using DataTables server side code as I have a custom API which drives the website.
Hope that clarifies.
Yes, that sounds about right.
Thanks for the clarification - I thought that it was the file upload that you wantted hidden, rather than specific fields!
Allan