Server Side Processing Add New Row

Server Side Processing Add New Row

MichaelPineMichaelPine Posts: 7Questions: 0Answers: 0
edited August 2012 in General
Been looking through the API internal and external, but not sure if there is something that will do what I want or the best stategy to make it happen. So my scenario is I have a paginated serverside processing table on a screen, the User gets a jQuery dialog to Add or Edit a particular record pretty basic, their requirement is when the add a new record to actually go to that new record, now given filtering and sorting, it could be that the new Record may not even be visible or I have no idea what page it will be on. Any ideas on the best way to go about doing this ?

Best I had come up with so far was to fake the data call to my server processing and get information back about what page a certain record would appear on and then after a redraw, go the particular page and row, sound ok ?

cheers
Michael

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Yup - that sounds like more or less what I would do as well. Make the call to the server to add the row in the database and have it return the page number that the row will be on. When have DataTables page to that row, and the draw call that makes will get the new row and display it.

    Allan
  • MichaelPineMichaelPine Posts: 7Questions: 0Answers: 0
    Thanks for the reply Allan, that was really quite painful and I know the reason behind the functionality, but it was quite painful. After the record was saved, redrew the grid and when my ajax call to find out where the new row is finished I then used fnPageChange to go the appropriate Row, slightly worried about my call to find where the new Row is degrading if they add LOTS of projects but not too concerned in the short term.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    When using client-side processing, you can use a technique such as that used in this plug-in: http://datatables.net/plug-ins/api#fnAddDataAndDisplay . However, when using server-side processing its a bit more complicated, as you've seen. DataTables on the client-side has absolutely no concept of where the row should be displayed, since the data is held at the server - so its up to the server to tell the client-side where the row is, and what page should be displayed.

    I'm not sure if there is a nice easy SQL command that would tell you what page a row would appear on - which is where I would imagine the scaling issue would occur. Off the top of my head, its just a case of getting all rows up until the new row and then dividing by the paging length - but someone more competent in SQL might be able to offer a better solution!

    Allan
This discussion has been closed.