Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5934287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:05:35+00:00 2026-05-22T15:05:35+00:00

I have a table that has 100% width. It is generated dynamically with values

  • 0

I have a table that has 100% width. It is generated dynamically with values from my db. I need to truncate TH values if they do not fit in the table, without pushing the boundaries of the cell. If the value is truncated I’d like to add a link with … and put the full length label into title tag. I don’t need it to expand. Something like this:

<th>
   Long label<a href="javascript:void(0)" title="$myFullValue">...</a>
</th>

I’m not sure how to get the value of the string…

$("TH").width();
$("TH").val().width(); ??

I know there are some jQuery plugins out there but I was not able to find what I need and I thought I could try and give this project my own whirl.

http://jsfiddle.net/b3cQZ/3/


EDIT:

Just an idea that crossed my mind. Couldn’t I wrap the label in tags and get it’s width. At the same time get the width of the parent TH. If labe’s width is greater, I could

  1. subtract, say 20 px (for …) from TH width and,
  2. assign that width to span’s width
  3. while adding overflow:hidden, and
  4. appending “…” to the span

Won’t this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:05:36+00:00Added an answer on May 22, 2026 at 3:05 pm

    This solution uses a fixed value but if you’re able to find a way to calculate the maxLength you could wrap this in a function and pass it the output as the maxLength.

    FIDDLE http://jsfiddle.net/m72Ja/2/

    HTML

    <table class="MyTable" border="1" width="400">
        <thead>
            <tr>
                <th>Col 1</th>
                <th>Col 2</th>
                <th>Long Long Long Col 3</th>
                <th>Col 4</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Data</td>
                <td>Data</td>
                <td>Data</td>
                <td>Data</td>
            </tr>
        </tbody>
    </table>
    

    JS

    $(document).ready(function() {
        $('.MyTable th').each(function() {
            var maxLength = 10;
            //if the value is greater than max length,      
            //cut the string to max length then add ...     
            if ($(this).text().length > maxLength) {
                $(this).text($(this).text().substring(0, maxLength));
                $(this).append($("<a href='javascript:void(0);' title='$myFullValue'>...</a>"));
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pictures table that has the following columns: PICTURE_ID int IDENTITY(1000,1) NOT
I have a datatable which has been dynamically generated from FoxPro tables using a
I have a table that has redundant data and I'm trying to identify all
I have a table that has an insert trigger on it. If I insert
I have a table that has a processed_timestamp column -- if a record has
I have a table that has a primary key that's an INT... I have
I have a table that has 8 million records, with many fields, including lat/long
I have a table that has about 1/2 million records in it. Each month
Suppose I have a database table that has a timedate column of the last
I have a table in MySQL that has 3 fields and I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.