Add a row to an empty table using datatables and use editor to edit the new row
Add a row to an empty table using datatables and use editor to edit the new row
pcpartner
Posts: 6Questions: 2Answers: 0
We can add a row as shown in this example https://datatables.net/examples/api/add_row.html but we would like to inline edit the newly created row afterwards. I can't find an example or information for how to do this.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Assuming that the row has been added using the same data structure as the rest of the DataTable, it should just work automatically.
The key thing here is that the row must have a primary key value.
I'm guessing, correct me if I am wrong, that you are using
row.add()
to add a new row and then inline editing to make it appear that a new row can be created via inline editing? I'm afraid that is not the case since it doesn't have a primary key value (which would require the row to be added on the database).What you could do is use
create()
to add a new row and that would submit it to the server and then allow regular inline editing.Allan
Allan, thx for the prompt response.
We are now able to add the row to the database through editor.create but I can't seem to find a way to redraw the table with the new created row.
Our code:
Hi,
When the
create
Ajax request is sent to the server, what is the response from the server. My guess is that it is an object with an empty data array, possibly caused by thewhere
condition that is being used above.The where condition is basically doing:
Note the quotes - it is using the second parameter as a string because it is being escaped automatically by the library for security.
Before we discuss how that could be addressed, could you say why that
WHERE
condition is there? I don't think it is actually doing anything (if it were to work) since it is just doingInvoiceCode = InvoiceCode
on the same table.Allan
Hi Allan,
It is indeed an empty data object
In the header of the invoice I create a new invoice number, once the invoice headers is created i would like to add row(s) to the invoice related to this new invoice number.
Therefore I would like to use the posted InvoiceCode value in the WHERE clause
I've figured it out
$invoicecode = isset($_POST['data'][0]['CF_InvoiceElements']['InvoiceCode']) ? $_POST['data'][0]['CF_InvoiceElements']['InvoiceCode'] : "dummy";
Is your
id
column an auto incrementing sequence? Editor should really do that for you and there should be no need to specify awhere
condition just to limit the response to the newly created row.Allan