Determination of Vertical Position in a Displayed Table

I am trying to incorporate infinite scrolling with an AJAX-based loader in the body of an HTML table.

Here is a snippet of my HTML code:

<table>
  <thead>
    <tr><th>Column</th></tr>
  </thead>
  <tbody>
    <tr><td>Row 1</td></tr>
    <tr><td>Row 2</td></tr>
  </tbody>
</table>

I have added CSS styling to create a scroll bar within the <tbody>:

tbody {
  height:10em; /* Prevents tbody from expanding to show all rows */
  overflow:auto;
}

In order to detect when the user scrolls to the bottom, I need to access the scroll position of the <tbody>. Most existing infinite scroll implementations using jQuery involve subtracting the content height from the container height and comparing it to the .scrollTop() value (like this one).

However, this approach may not work with the <tbody>, as it serves as both the viewport and container for the scrolled content. While $("tbody").height() returns the viewable size, I am unsure how to obtain the full (viewable + hidden) size of the table body. Notably, $("tbody").scrollTop() correctly provides a larger number when scrolled to the bottom as expected.

Is there a way to overcome this challenge?

Answer №1

tableBody.clientHeight is the solution for me.

Answer №2

When you want to access the hidden height, you can set the height to auto temporarily, get the value, and then revert back to the original size.

let $tableBody = $('tbody');
let initialHeight = $tableBody.height();
$tableBody.css('height','auto');
let autoHeight = $tableBody.height();
$tableBody.css('height',initialHeight);

This technique should work quickly even in Internet Explorer without any visible flickering to the human eye.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to incorporate a custom string into an Angular application URL without disrupting its regular operation?

In my Angular application with angular ui-router, I am facing an issue with the URL structure. When I access the application from the server, the URL looks like localhost/..../index.html. Once I click on a state, the URL changes to localhost/.../index.htm ...

Guide to executing an efficient Graphql request in Vue using Apollo

Seeking assistance with configuring my initial queries on scaphold.io. Here is the query I am running through the internal GraphiQL: query AllPrograms { viewer { allPrograms{ edges { node { id name } ...

Ways to confirm that the function handed over as a prop to a Vue component operates asynchronously

How can I determine if a prop Function is asynchronous? Consider the following prop in my component: callbackFunction: { type: Function, default: null, }, Is there a way to validate this and ensure that the provided Function i ...

Determine the class name of an element when it is clicked on

For various reasons, I am unable to use $('.class').click or on('click', function..) Therefore, I must utilize the onclick="" event from the html element. Is there a way to determine the class of the element where the onclick event oc ...

Looking for a reliable CSS aggregator for .Net that can merge and minimize style sheets effectively?

Is there an open source or free project that offers a CSS manager? I want to optimize performance and am hoping to find a pre-built solution rather than starting from scratch. Some key features I'm looking for include: Merging multiple .css files in ...

`Issue with input focus in jQuery``

According to the documentation for jQuery's focus() method, the following code should make the input focused (active): $('#id').focus() However, I'm having trouble getting this to work. Even when trying it in the console on this webs ...

Filtering Jquery datatable results by text

In order to filter records from a jQuery data table, I have utilized the following code. The format for my data table is as follows: var aDataSet = [['1', 'GOld', 'G-110,G-112,G-123', 'G1-001,G1-005,G1-008'], ...

Mastering the art of extracting elements from an HTML Dygraph

Attempting to extract all data points from this particular website utilizing BeautifulSoup and requests in Python. The current code in progress is as follows: session = requests.Session() page = session.get(https://bitinfocharts.com/comparison/bitcoin-tra ...

The CORS Policy error message "The 'Access-Control-Allow-Origin' header is missing on the requested resource" in Next.js

Encountered an issue with CORS Policy error while attempting to redirect to a different domain outside of the project. For example, trying to navigate to https://www.google.com through a button click or before certain pages load. The redirection was handl ...

Separate the elements with a delimiter

I am in the process of inserting various links into a division by iterating through a group of other elements. The script appears to be as follows $('.js-section').children().each(function() { var initial = $(this).data('initial'); ...

The latest changes in the MongoDB route and model may result in either data deletion or an error being thrown

I've been searching for quite some time now, and I haven't found a similar issue to the one I am facing. Working on a MERN stack application with four routes, three are functioning properly. However, the fourth route and the database model are c ...

problem with collapsible dynamic Form List

I'm facing a challenge with implementing dynamic form submission. You can view my code here. The data is being retrieved from the backend. const dataFromBackend = [ { id: 2, start: "2022-01-04T08:00:00.000Z", money: "500" ...

The @Html.Label feature fails to appear when the content includes a period (.) - Utilizing Bootstrap with MVC Razor

I am dynamically populating label text from a database source <div class="col-11 col-sm-11 col-md-11 col-lg-11 col-xl-11"> @Html.Label(@Model.Questions[i].DataText + ": ", new { @for = "dd" + @Model.Questions[i].Data ...

Having trouble retrieving a hidden value in JavaScript when dealing with multiple records in a Coldfusion table

In this table, there is a column that allows users to select a predicted time. <cfoutput query="getReservations"> <tbody> <td><input class="form-control predicted" name="predicted" id="ReservaTempoPrevisto" placeholder= ...

Guide to incorporating @types/module with the corresponding npm module that has type definitions available

This is an example of a module I am currently utilizing in my project. I have come across TypeScript type definitions for the npm module polylabel, which can be found at https://github.com/mapbox/polylabel. When I run npm install --save @types/polylabel, ...

Preventing jQuery slideToggle functionality from toggling multiple elements at once

I am currently working on a project where I have a series of images with captions that appear underneath each one. To show or hide the caption for each image, I am using slideToggle when the image is clicked. $('.imageholder').click(function() ...

Suggestions for resetting the input field IDs in a cloned div after deletion

In the given HTML code snippet, there is a <div> containing two input fields as shown below: <button type = "button" id = "add-botton" >Add Element </button> <div id = "trace-div1" class = "trace"> <h4><span>Trac ...

Retrieving the text content from a JSON key

I have the following JSON data saved in a jQuery variable called "jsondata": var jsondata = { "Name": { "Jaken": {}, "Test": {}, "Hello": {} }, "Date": { "Today": {}, "Tomorrow": {}, "Wednesday": {} }, "Description": { ...

Transform the file format from .casa-model to .obj

Looking for a way to convert a file with the extension .casa-model to .obj format. Is there any solution available? Find the model here. ...

Having trouble getting SVG animations to work properly when using the static folder in Parcel?

As I was attempting to display my SVG file on the browser after uploading it to my domain, I followed a similar process to other projects where I had installed parcel. This involved creating a static folder and placing the SVG file inside it. While the SVG ...