Replace on create?

Replace on create?

tinncuptinncup Posts: 10Questions: 3Answers: 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

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I think what you will need to do here is call ajax.reload() in a submitComplete event handler.

    On a create action Editor's interaction with DataTables doesn't do anything other than call row.add(), so the row is always going to be added to the DataTable with the default code.

    Allan

  • tinncuptinncup Posts: 10Questions: 3Answers: 0

    Thank you - is there an example by chance?

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    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:

    1. Why does it send 27 rows after trying to create a new row. You can see this with the browser's network inspector tool.
    2. The returned data doesn't include the newly created row. Maybe I didn't populate enough fields for the server side insert to work.

    Kevin

  • tinncuptinncup Posts: 10Questions: 3Answers: 0
    edited June 2022

    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?

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    edited June 2022

    The test case is now returning a 500 Internal Server error. Please investigate the server logs to debug.

    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?

    If you look at the doc I posted the Editor expects just the newly added row:

    Server replies with the data parameter defining the data object for the newly created 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 execute ajax.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

  • tinncuptinncup Posts: 10Questions: 3Answers: 0
    edited June 2022

    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.

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Use the submitComplete link Allan provided above.

    Kevin

  • tinncuptinncup Posts: 10Questions: 3Answers: 0

    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?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    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:

    editor.on('submitComplete', function () {
      table.ajax.reload();
    });
    

    Allan

Sign In or Register to comment.