Jump to a row without scroller enabled
Jump to a row without scroller enabled
I have a table where I'd like to jump to a specific row, but I don't see that capability aside from scrollTo
.
I'm utilizing vertical fitting:
https://datatables.net/blog/2017-12-31
Plus I also have a button that expands the table to show more rows, but when it does that it returns to the top of the table.
buttons: [{
name: "expand_compress_season_data",
text: "<i class=\"fad fa-expand-alt fa-fw\" id=\"expand_compress_season_data_icon\"></i>",
attr: {
title: "Expand and compress season data",
id: "expand_compress_season_data"
},
action: function () {
// Change button icon
$("#expand_compress_season_data_icon")
.toggleClass("fa-expand-alt fa-compress-alt");
// Determine if expanded
var expanded = $("#expand_compress_season_data_icon")
.hasClass("fa-compress-alt");
// Expand table and change to nonfluid
$("#season_slicer_control_wrapper table")
.toggleClass("table-nonfluid");
$("#season_slicer_control_wrapper")
.toggleClass("fw-35 min-lg");
// Show columns with expandable class
season_slicer
.columns(".expandable")
.visible(expanded);
// Get index of currently selected row
var current_index = season_slicer
.row(".selected")
.index(); // I'm able to get the row index
// Redraw table and go to current index
season_slicer
.draw()
.row(current_index)
.scrollTo(false); // But unable to use scrollTo to get to the row
}
}]
Once I get the row index, is there an api function to jump to that row without using Scroller? And I'm not using Scroller because I'm using the vertical fitting.
This question has an accepted answers - jump to answer
Answers
See if the row().show() plugin or the page.jumpToData() plugin does what you want.
Kevin
Thanks, Kevin (@kthorngren), I had looked at those but they jump to the page and not the specific row.
The issue when using the "vertical fitting" approach is there is no paging -- the entire table is shown inside a div (the
resize_wrapper
), which may or may not show the whole table depending on how large the window has been made.Wait wait wait . . .
I simply need to pass the
"full-hold"
parameter to thedraw()
event.It doesn't do exactly what I was asking, which is jump to a specific row, but the effect is what I'm essentially looking for -- the
draw()
doesn't reset the table to the top.Oddly, I've done this on a dozen other tables before, but after programming all day it's hard to think through some obvious things after a while.
But currently it's 8am for me and I've just finished my first cup of coffee, so naturally while looking out a window and wondering why I didn't mow the yard this past weekend, the correct approach occurs to me out of the blue!
Also, @allan, we can't mark our own questions as answered by ourselves, but you can mark this one as answered for me.
Thanks!
Done