Jump to a row without scroller enabled

Jump to a row without scroller enabled

Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9
edited July 5 in DataTables 1.10

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

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    See if the row().show() plugin or the page.jumpToData() plugin does what you want.

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9

    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.

  • Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9
    edited July 6 Answer ✓

    Wait wait wait . . .

    I simply need to pass the "full-hold" parameter to the draw() 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!

  • Loren MaxwellLoren Maxwell Posts: 272Questions: 60Answers: 9

    Also, @allan, we can't mark our own questions as answered by ourselves, but you can mark this one as answered for me.

    Thanks!

  • colincolin Posts: 9,175Questions: 0Answers: 1,533

    Done :)

Sign In or Register to comment.