finding which page has newly created data in the serverside datatable
finding which page has newly created data in the serverside datatable
SweetAnonymous
Posts: 18Questions: 1Answers: 0
How to find out which page has newly created data in the serverside datatable.
How to display page dyamically? say for example need to display 3rd page by default dyanamically?
This discussion has been closed.
Replies
That depends on your server side environment. How is the new data created? What mechanism would you use to notify Datatables of the change in the Database?
You would use the
page()
API to display a different page. The first page is 0 so the third would be 2. You would usepage(2).draw()
.Kevin
I created a new row and i know newly created column (Id) value, my requirement is to redirect to the home page (datatable exists page) highlight the newly created row and display that new created data page.
Sounds like you are using server side processing (
serverSide: true
). In this case you would need to have your server script determine the page to display or page data to return. One option may be to use theapi page.info()
API to get the current page length, send that via ajax to the server and have it calculate and return the page number. Then use thepage()
API to request that page's data from the server. There may be other better ways to do this depending on your environment.However if your data was client side you could use
ajax.reload()
to refresh the data then use the row().show() plugin to display the page. I believe this will work only with client side data. See this thread about using something similar with server side processing.https://datatables.net/forums/discussion/comment/124265/#Comment_124265
Kevin
How to find the data in the server side datatable. Lets say, ID 456 need to find the 456 id row and display that page. What is the syntax to find the data in the server side datatable.
Or find the page number where my data exists?
Depends on what your data source is. I suspect the approach would be to send an ajax request to the server using the information Allan mentioned in the last post of the above thread. The server script would then process a sql query or other code (depending on the data source) to find where the desired data is located and return a page number. Then, as mentioned in that thread, use the
page()
API to go to that page.Probably not a trivial task.
Kevin
@kthorngren :
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Thanks for your quick reply.
What is wrong here, i tried to display page(1) in document.ready like below
$('#tblIndexEmployee').DataTable().page(2).draw('page');
It did not work either.
and also i tried
"displayStart": 11 attribute. It does not work.
Here is an example of using
page
with server side processing:http://live.datatables.net/lezupisi/1/edit
The problem with your
initComplete
code is the variableoTable
hasn't been created yet.You will probably see an error in the browser's console for this. I'm not sure you can go to another page in initCompelte. The
displayStart
works here:http://live.datatables.net/nilemina/1/edit
Please update either test case to replicate your issue.
To troubleshoot your environment I would first look at the browser's console for errors. Next I would monitor the
xhr
request/response using the browser's developer tools. This should show whether the page request is going to the server or not. But without actually seeing the problem happen it would be hard to debug.Kevin
I was able to do it. I get the row value from the datatable and look for the value and calculated the page no using lengthmenusettings and found the page No and called
oTable.page(1).draw('page'); after datatable is build. Thank you Kevin
I have a new problem now. I am not able to click on the page no and next button. Here is my code.
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.2.1/dt-1.10.16/cr-1.4.1/fh-3.1.3/r-2.2.1/datatables.min.css" />
function DrawIndexNonEmployeeDetails(nonEmpParameters, userId, lengthAll) {
}
Hard to say what the problem might be. What happens when you click on the page number or next button?
Do you see errors in the browser's console?
Do you see an ajax request sent and response in the browser's developer tools?
Kevin
Nothing happens. no errors. I think its in disabled mode
Can you post a link to your page so we can take a look?
Kevin
I change the references, Its working fine. Thanks Kevin