SSP and row.add().draw() again

SSP and row.add().draw() again

pintrespintres Posts: 5Questions: 2Answers: 0

I am aware of what's the purpose and what's going on after calling row.add().draw() with SSP but...

I have an application which uses DataTables for displaying relational data within edit form of the object. I'm migrating it to SSP now for it started to use large number of records and it all works fine but..
The very core structure of the app is based on serialising and saving the form after the button 'save' is clicked. Each row of the 'relation-displaying' table contains hidden field with relational object ID. This whole DT-table is then serialised and send to the server for further processing.
When I want to add sth to the relation there is a modal window to let me select what's to be added. Up to now the new "rows" were appearing within appropriate DT on the screen. Clicking 'save' I was confirming it, sending to the server for further processing and displaying everything again from updated datasource.

QUESTION:
What would be your suggestion for such 'two-steps' relational "row (data)" adding after changing it all to SSP?

Of course I can add it server side but then I'm losing the 'confirmation' stage. All the same if I save just the 'relationship' data it will be wrong for the whole UI...

Any suggestions? Thank you in advance!

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    It would be worth considering Editor, as it's ideal for that kind of scenario. The alternative would be to create the end-point on the server yourself to retrieve the data and update the database.

    Clin

  • pintrespintres Posts: 5Questions: 2Answers: 0

    Just another idea - is it possible to "temporary turn off" SSP for certain table? I'm just thinking if after selecting "new rows" I can run the DT constructor again with SSP turned off for this certain table? Or maybe prepare second table with "new rows only"? Or maybe replace HTML table with AJAX and then run the constructor with SSP disabled? I wonder if anybody ever tried sth similar and/or consider it a good idea. What do you think please?

  • allanallan Posts: 63,200Questions: 1Answers: 10,414 Site admin

    The key take away here is that the client-side row.add() method should not be used with server-side processing at all!

    Consider that you have 100 records being displayed in a 10 records per page table, sorting and filtering applied. If you added a new record, where should it go? DataTables can't know if it should go into the current page or another one, and if it does go into the current page, which record should be removed from the page. The reason it can't know those answers is that the full data set is not available at the client-side - its only at the server-side, which will do the sorting and filtering (and paging).

    So the way to add new rows when you have server-side processing enabled is to add it to your data source (presumably an SQL database) and then call draw() to load the latest data, allowing the server to do sorting / filtering.

    Does that make sense now?

    Allan

  • pintrespintres Posts: 5Questions: 2Answers: 0

    Hi Allan,

    Thank you for your replay. Yes it makes sense from the very beginning of my post - I've already read other discussions in this area and I do get the idea very well. Even more - I do agree with your approach. I'm just wondering if there is any other method I'm not aware of that can help me with keeping both DT and two-steps confirmation. What I'm thinking about now is (as written in my previous comment) creating complementary table with new rows only. Then it can be client-side displayed and combined with the original dataset (PostgreSQL) after confirming the changes with "save" button. Then calling draw() on the original DT will refresh the data just as you explained.

    One more time thank you for your answer and time!

This discussion has been closed.