Replace on create?
Replace on create?
tinncup
Posts: 15Questions: 5Answers: 0
Link to test case: test.gunnarstone.com (dragoncat/cat2022)
Debugger code (debug.datatables.net): NA
Error messages shown: NA
Description of problem: I need to allow the user to add a row at any location in a dataset. Server code handles the insertion and returns the complete and ordered dataset, however the returned dataset is appended to the current table. Can DT replace instead of append on a create? What is the preferred way of achieving a basic insertion with DT?
Answers
I think what you will need to do here is call
ajax.reload()
in asubmitComplete
event handler.On a
create
action Editor's interaction with DataTables doesn't do anything other than callrow.add()
, so the row is always going to be added to the DataTable with the default code.Allan
Thank you - is there an example by chance?
In your test case I tried creating a new row but the server doesn't seem to return the row I created. instead it returns many rows, looks like duplicated rows, instead of the expected new row. See the Editor client/server docs for the expected response.
I would start by looking at the server script for two issues:
Kevin
Sorry - would have helped if I had deployed the development test case - now complete..
Clearing the cache allows a reset to the base data case.
To be clear - the server tries to process in line number as a row insertion point and is coded to return the complete dataset, which appears to get appended to the existing table? Because the row could be inserted anywhere and the dataset is not sortable (machine commands), the server is coded to complete the work. Really it is a row insert - maybe I misunderstood the indent of the "create" button?
The test case is now returning a 500 Internal Server error. Please investigate the server logs to debug.
If you look at the doc I posted the Editor expects just the newly added row:
If your server script returns all the rows then its not behaving as Editor expects. The Editor will insert whatever is returned from the server. The idea is that the server script will insert the row into the DB. Then will fetch the row from the DB to pickup any DB specific things that could happen with the inserted data, like an auto increment field. Then the server script returns the data fetched from the DB. The user will then see an exact representation of what is in the DB.
However if you can't do this then Allan's suggestion of using the
submitComplete
to executeajax.reload()
will refresh the data from the server. Although not the same as Allan's suggestion this example shows how to use Editor events.Kevin
Thank you and apologies for the 500. The link to submitComplete does not seem to resolve (404). - so I am not sure what it actually does or the design use.
Use the submitComplete link Allan provided above.
Kevin
Thanks - I will give it a shot. My trial is quickly expiring. Would it be possible to get a 5 day extension on the trial license?
I've just removed your existing trial, so when you download a fresh copy it will start a new 15 day trial for you.
In case you haven't been able to put it together, this is the code to refresh the table:
Allan