• Resolved pauldotmac

    (@pauldotmac)


    Hi, I want to make a table fixed on a page as the page starts to scroll. The table is not intitally in view but as the user scrolls down it comes into view and once it gets to the top of the page I want it to stay there. I’ve found some code which will do this and it uses jQuery to locate and fixed the position of the table. The following Code Snippet – another great plugin – contains my Javascript / jQuery code

    if (jQuery("div#tablepress-7_wrapper")){
    console.log("Hello World");
    let tp7_wrap = jQuery("div#tablepress-7_wrapper");
    console.log(jQuery("div#tablepress-7_wrapper").html());
    }

    The code is inside a jquery(document)ready statement to make sure that the page is fully loaded prior to the interrogation of the element. “Hello World” prints to the console, so the previous line is working but when I try to read any property of the tablepress div element all I get is undefined. Clearly the element is there so why can’t I read any of its properties?

    Thanks

    Paul

Viewing 1 replies (of 1 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi Paul,

    most likely, your code is running too early, before the DOM element has actually been added to the page (which also happens using .ready()). That if (jQuery("div#tablepress-7_wrapper")) is not sufficient here, I believe because that always returns true. You will probably need to check with if (jQuery("div#tablepress-7_wrapper").length).

    By the way: If you are looking for a way to make the header sticky, you could check out this feature of the premium versions: https://tablepress.org/modules/datatables-fixedheader-fixedcolumns/

    If you want to make the entire table sticky, you could maybe also use CSS, with position: sticky;.

    Best wishes,
    Tobias

Viewing 1 replies (of 1 total)

The topic ‘Using jQuery with Tablepress to get table offset()’ is closed to new replies.