Adjust the width of the table after refreshing it for 10 seconds when resizing the column?

I am facing an issue with a page that refreshes every 10 seconds and has a resizable column feature.

However, after the page refresh, the table header (th) reverts back to its original position.

The main question is how to obtain the width of a specific th after resizing it and then apply that width only to that th so that the user can see the resized th after the table refreshes.

Which jQuery event can be used to get the width of a th when it is resized, and what method can be used to apply this width only to that particular th without affecting others?

div {
  resize: horizontal;
  overflow: auto;
}

td {
  text-align: center;
}
<div id="banner-message">
  <table cellpadding="0" cellspacing="0" border="0>
    <thead>
      <tr>
        <th>
          <div>One</div>
        </th>
        <th>
          <div>Two</div>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>ab</td>
        <td>cd</td>
      </tr>
    </tbody>
  </table>

</div>

Answer №1

The challenge you may face is not having access to user-defined widths. Upon landing on a page, whether by refreshing or initial entry, default values are what you're left with.

To address this issue, one effective method is to include parameters in the URL. This allows you to subsequently retrieve these values from the URL and utilize them for setting the width. Alternatively, utilizing localStorage or sessionStorage can also be beneficial. However, keep in mind that passing set widths via a URL is not feasible with this approach. Don't forget to update the values once a change has been detected.

Answer №2

Received the solution

Inserted a new div element inside th

<th><div>#</div></th>

1. To adjust column size

$("#thead_DispatchTrip th").resizable({
        handles: "e",
        resize: function (event, ui) {
            $(ui.element).find('div').width(ui.size.width);
        }
    });

2. For obtaining width

tableWidth = [];
    $("#thead_DispatchTrip th").each(function () {
        tableWidth.push($(this).find('div').width());
    });

3. For setting width after 10 seconds

$("#thead_DispatchTrip th").each(function (i,el) {
    $(this).find('div').width(tableWidth[i]);
});

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

Retrieve a different action instance variable within the view

In the scenario where I have a View called home.html.erb and the corresponding controller shown below: class StaticController < ApplicationController def home @people = Person.all end def filter @people = .... end def contact end ...

Using ngTable within an AngularJS application

While working on my angularjs application, I encountered an issue with ngtable during the grunt build process. It seems that the references are missing, resulting in the following error: Uncaught Error: [$injector:modulerr] Failed to instantiate module pa ...

output the array utilizing map function results in undefined

I have an array structured like this: const HeaderData = [ { header: { title: "How you`ll benefit", detail: "We create these goals to assist you in recovering from your recent surgery. Slowly increasing your physica ...

Tips for exchanging JavaScript variables with PHP using AJAX

Hey there, I'm new to JavaScript and I've hit a roadblock with passing variables to PHP using Ajax. <script> $date = "123"; $.ajax({ url: './record.php', type: "POST", ...

The responsiveness of Bootstrap 5 columns in Chrome inspection appears to break after reaching medium size, yet functions properly in other areas

I am currently working with cards within a grid system, but I am encountering an issue with resizing when the column size is smaller than medium in the mobile view inside the inspect section. The width does not expand to 100%, regardless of how much I try ...

Positioning three divs next to each other and aligning them at the bottom of the longest div

While I've seen similar questions about aligning divs in a row, my situation has a slightly different twist. I have three divs that I want aligned horizontally, with their content pushed to the bottom. I've attempted using position: relative and ...

Error: Invalid argument type

I'm encountering difficulties retrieving data from an API as I delve into learning Angular 2. The error message I am facing is: url.js:106 throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string', url); Typ ...

Merging an AppBar and Drawer in Material UI for a seamless user interface design

I am working on integrating an AppBar component with a drawer feature. Here is the code for the AppBar: import React from "react"; import PropTypes from "prop-types"; import { withStyles } from "material-ui/styles"; import AppBar from "material-ui/AppBar" ...

Dropmenu | Designing with Materials | Pair of Choices | Intersection

My goal is to incorporate dropdown fields with material design only. After researching various examples online, I have noticed a recurring issue. When there are two dropdown items close to each other, they end up overlapping. Check out this example: http ...

Updating the language of the months displayed in the popup calendar

I am attempting to change the language of the clickDate function from English (Jan, Dec, etc.) to another language. However, I am struggling to find a way to do so because I only have access to the scripts provided below. The idate is in the format 2015073 ...

Having trouble extracting a value from a JSON object in JavaScript

I am encountering an issue while attempting to extract a specific value nested within a JSON object. The API call response is provided below. var responseData = { "statusCode": 200, "body": "{\"Errors\":\"\",\"Message\":n ...

Is it possible to share a Vue.js component by "transferring" it rather than duplicating it?

In my comment system project using Vue.js, I have over 300 comments to manage. Each comment has an admin section that appears when the cursor hovers over it. Duplicating the admin section component for each comment is not ideal as it creates unnecessary l ...

Elevate your website's design with Vue and create eye-catching CSS

I've been working on a Vue hamburger menu component, but I'm facing an issue with the animations. The animation process seems to reach the desired end result, yet there is no actual animation displayed. The animation triggering is done through a ...

Encountering a Javascript error while trying to optimize bundling operations

After bundling my JavaScript with the .net setting BundleTable.EnableOptimizations = true;, I've encountered a peculiar issue. Here's the snippet of the generated code causing the error (simplified): var somVar = new b({ searchUrl: "/so ...

Improve the efficiency of loading and utilizing data from the petition using $http

In my Ionic framework application, I am dealing with a large amount of data - around 10,000 records initially, with an additional 200 records being added every week. However, the loading time for this information is becoming a concern as certain sections o ...

The element residing within the body exceeds the body's dimensions

HTML : <body> <header> <div> </div> </header> </body> CSS : body { width : 1000px ; } header { width : 100% ; } If these codes are implemented, The header's width should be the same as the body's ...

Incorporating lazy loading for diverse content to enhance pagination

I'm currently using jpaginate for pagination on a large dataset, but I've noticed that all the content loads at once. Is there a jQuery plugin available that will only load the content for the current page? ...

Adding an audio event listener in HTML5

I am having trouble maintaining the limited loop functionality in my HTML5 audioplayer when I try to replace it with buttons and add event handlers to them. The repeat function only seems to work if the checkbox is checked and the second option of the se ...

How can a server retrieve a file uploaded using FormData and Ajax on a cross-domain upload?

my website is running on localhost:8084 and I need to upload a file to localhost:8086. Below is the JavaScript code: var xhr = new XMLHttpRequest(); xhr.open("post", "http://localshot:8086"+ "?type=ajax",true); xhr.setRequestHeader("X-Reque ...

Working with handleChange and onSubmit functions in pure JavaScript without any libraries

Currently developing my initial app, which is a login/register form using JS/Node.js/MySQL. I am facing issues with connecting my form to the database in order to store user data. I haven't utilized "handleChange" or "onSubmit" functions as I am not e ...