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

  • SEARCH
  • Home
  • 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 8733205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:36:15+00:00 2026-06-13T09:36:15+00:00

I am using the jQuery DataTables plugin. I don’t want my thead columns to

  • 0

I am using the jQuery DataTables plugin. I don’t want my thead columns to line up with the tbody columns, as I am mostly using the header columns as sorting buttons. The header names no longer really fit because I am displaying extra information in the body columns.

I would like the thead columns close together and left aligned at the top of the table. I want the tbody columns to be auto-sized the way DataTables usually works. What is the best way to accomplish this styling?

Also, I feel as though I am abusing DataTables and the table element in general. If you are aware of a cleaner solution to my problem that does not involve rolling my own ajax (for retrieving the table data), sorting, pagination, and filtering, please let me know.

  • 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-06-13T09:36:16+00:00Added an answer on June 13, 2026 at 9:36 am

    Remember that in the end, it’s a table. the structure of a table is hard to change and the widths of the headers will follow the widths of the body that they encompass.

    You say that you are using extra information for sorting? Why not create a container using whatever structure and css you want and then interact with datatables using the api?

    You can sort using the api:

    $(document).ready(function() {
      var oTable = $('#example').dataTable();
    
      // Sort immediately with columns 0 and 1
      oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
     } );
    

    For instance, if you’d rather have a button above the table that the user can click instead of the table header themselves, you can do this:

    <div id="separateStyledContainer">
        <button id="sortByColumn2">Sort by Column 2</button>
    </div>
    <table id="datatable">
        <thead>
            <th>Column 1</th>
            <th>Column 2</th>
        </thead>
        <tbody>
            <tr>
                <td>Column 1 Value 1</td>
                <td>Column 2 Value 1</td>
            </tr>
            <tr>
                <td>Column 1 Value 2</td>
                <td>Column 2 Value 2</td>
            </tr>
        </tbody>              
    </table>
    

    And here’s the JS:

    $(function() {
    
      var table = $("#datatable").dataTable();  
    
        $("#sortByColumn2").on("click", function() {
          table.fnSort([[1,'asc']]);             
        });        
    
    })​
    

    Here’s a working jsFiddle to check out

    This way you’re not fighting against the table. All of the APIs that datatable makes available are here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the datatables jquery plugin and want to sorty by dates. I
I am using the jquery plugin DataTables for table sorting and manipulation. In a
I'm using Datatables and have this jquery plugin showing in a few columns http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
I am using jQuery Datatables plugin and I want to add some extra content
I am using the DataTables jQuery plugin. The way I want my tables to
I am using the jQuery DataTables plugin. I would like to move the search
I am using the jQuery DataTables plugin to do filtering on a set of
I am using the jquery plugin datatables and am trying to take advantage of
I'm using the latest version of the jquery plugin DataTables and I tried to
I have started using the DataTables plugin (v1.6.2) for jQuery (v1.4.2), and I would

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.