johnw65's avatar

Datatable Server-Side Pagination for Newly Added Record

I'm currently using Datables 1.10 and is using Server-Side with Pagination (which is dynamic based on the screen size using PageResize plugin: https://datatables.net/blog/2015-04-10 ).

To show the selected row, I am using row().show() plugin: https://datatables.net/plug-ins/api/row().show()

My customer is requesting that once an user adds a new record, it should take the user to the appropriate page after a table.ajax.reload(). I can get the ID of a record and select it and can also pass the page length, but is unable to go to the correct page?

Is there any way that I can set the number of rows per page and loop through until I find the record while maintaining the sort order and the where clause?

How can I find the page number of this newly added selected row? I appreciate your assistance! Thanks.

0 likes
4 replies
jlrdw's avatar

How does the customer expect you to know the exact search that was done?

For example I might have searched for customers who's name starts with "wh".

But I may have just entered a new customer who's last name is Smith. You would need a whole new where clause. But then the original where clause would be gone. It is like a paradox.

But just my opinion on this.

Edit: Probably figure out the new search, calc number of pages, go to last page. But again original sort and where would be gone.

johnw65's avatar

Jlrdw,

I haven't used Datatables server-processing, but I believe I can pass the sort order and the where clause so after an insert, I can run the query and create pagination. Then since I know the ID of a newly inserted record, I need to loop through and find the correct page.

After an insert, I do have the record selected. But I just cannot go to the correct page. I'm stuck. Thanks.

jlrdw's avatar

I know that normally after an "edit" it is common to return to an index page where you left off. But usually after adding a record, you goto page one. Normally because you don't know where it is located within paginated pages.

But I admit this is a good one, I am still thinking about how I would do it.

I would probably do this:

  • user searched wh%
  • ordered by last name

They insert new record, say Fred White. Would it work if you just get them right back to their original search criteria. Fred White would be close. But if they entered Fred Wade, still return them to their original search, and they can find Fred Wade if they want to.

Just suggestions.

johnw65's avatar

Actually, if the new record does not meet the search criteria, then it doesn't need to be displayed. However, if there is no criteria or meets the criteria, then it needs to be displayed. The sort orders can be more than one columns.

I'm using Oracle so I'm looking at Oracle pagination right now. I'm trying to see whether there is a SQL command that would show the page number of a newly added row.

By the way, appreciate all of your assistance!

Please or to participate in this conversation.