Page of selected record
Page of selected record
How can I get the page index of the record currently selected?
My use case:
The user selects a record, all non-selected records are excluded from display. The user edits the record and saves it. Since the table order is influenced by the editing the selected record is usually no longer on the same page. Hence the user sees an empty page because the selected record - which is the only visible record - is no longer on that page. I would like to navigate to the page of the selected record on "submitSuccess".
This question has accepted answers - jump to:
Answers
There are a couple of plugins to show the page of the desired row:
https://datatables.net/plug-ins/api/
Maybe one of them will help.
Kevin
Hi Kevin,
thanks!
I looked at those plugins and this seemed to be relevant:
https://datatables.net/plug-ins/api/page.jumpToData()
I finally got this code working but it is so bad that I don't want to use it. I still haven't found a way to determine the position of a selected row in a data table. I needed to take a detour
- get the value of a field from the selected row (in my case "serial")
- assign a class to the column of that field in the HTML to be able to find it
- search for the value of "serial" in the right column of the selected row and determine the row's position as the "indexOf" the column cells
What I need is a direct way to determine the position of a selected row. And I learned: It is not its "index". That is something data tables internal that doesn't coincide with the rows position.
So this is the "bad" code that works:
This is what I would like to have but doesn't work because "index()" is not the position of the selected row:
Any ideas? Or maybe @allan ?
Roland
Of course I would prefer this over all that complicated stuff above. I guess that would require new API features. "row().page()" to get the page of the specified row.
I put together a simple example using row().show():
http://live.datatables.net/guwafemu/319/edit
Looks like this:
Kevin
Hey Kevin,
how come I overlooked Edouard's great plugin? I've got to be blind!
"row().show()" did the trick in just one line of code!
Many thanks for your help!
Roland
Yeah, that's awesome. Nice one
Allan