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 8775799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:53:43+00:00 2026-06-13T18:53:43+00:00

I have gone through the column sorting in jQuery datatable plugin and the various

  • 0

I have gone through the column sorting in jQuery datatable plugin and the various ways of controlling it.. I have a query is it possible to control sorting in such a way that clicking on upper arrow icon will do sorting in ascending order & down arrow icon will do sorting in descending order??

  • 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-13T18:53:45+00:00Added an answer on June 13, 2026 at 6:53 pm

    There is two way of doing that, depending on datatables version.

    EDIT for Datatables version 1.9 or less

    You need to use fnHeaderCallback. With this callback you can edit every th element in table header.

    I have create a working example for you.
    LIVE : http://live.datatables.net/oduzov
    CODE : http://live.datatables.net/oduzov/edit#javascript,html

    Here is code behind that (open snippet to see the code) :

    $(document).ready(function($) {
      var table = $('#example').dataTable({
        "fnHeaderCallback": function(nHead, aData, iStart, iEnd, aiDisplay) {
          // do this only once
          if ($(nHead).children("th").children("button").length === 0) {
            
            // button asc, but you can put img or something else insted
            var ascButton = $(document.createElement("button"))
              .text("asc");
            var descButton = $(document.createElement("button"))
              .text("desc"); // 
    
            ascButton.click(function(event) {
              var thElement = $(this).parent("th"); // parent TH element
              var columnIndex = thElement.parent().children("th").index(thElement); // index of parent TH element in header
    
              table.fnSort([
                [columnIndex, 'asc']
              ]); // sort call
    
              return false;
            });
    
            descButton.click(function(event) {
              var thElement = $(this).parent("th");
              var columnIndex = thElement.parent().children("th").index(thElement);
    
              table.fnSort([
                [columnIndex, 'desc']
              ]);
    
              return false;
            });
    
            $(nHead).children("th").append(ascButton, descButton);
          }
        }
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://legacy.datatables.net/release-datatables/media/js/jquery.dataTables.js"></script>
    <table id="example" class="display" width="100%">
      <thead>
        <tr>
          <th>Name</th>
          <th>Position</th>
          <th>Office</th>
          <th>Age</th>
          <th>Start date</th>
          <th>Salary</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th>Name</th>
          <th>Position</th>
          <th>Office</th>
          <th>Age</th>
          <th>Start date</th>
          <th>Salary</th>
        </tr>
      </tfoot>
      <tbody>
        <tr>
          <td>Tiger Nixon</td>
          <td>System Architect</td>
          <td>Edinburgh</td>
          <td>61</td>
          <td>2011/04/25</td>
          <td>$3,120</td>
        </tr>
        <tr>
          <td>Garrett Winters</td>
          <td>Director</td>
          <td>Edinburgh</td>
          <td>63</td>
          <td>2011/07/25</td>
          <td>$5,300</td>
        </tr>
      </tbody>
    </table>

    For Datatables version 1.10 and newer

    callback have a new name, it’s just headerCallback. Everything else is the same, so use new callback insted of legacy api.

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

Sidebar

Related Questions

I have gone through various udp based P2P Technology like Stun . I have
Have gone through hibernate api specification on FlushMode but didn't get the exact difference.
I have gone through Google and Stack Overflow search, but nowhere I was able
I have gone through this to change the color of my title bar. I'm
I have gone through this page... http://www.php.net/manual/en/function.hash.php MD5 is 32 characters long while sha1
I have gone through a couple of similar questions but could reach a definite
I have gone through the fadein/fadeout tutorial that is on this page: For the
I have gone through many posts on SO regarding this issue: Tried everything in
I have gone through different questions/articles on Message Brokers and ESBs(Even on stackoverflow). Still
I have gone through following question. Convert NSString to NSDictionary It is something different

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.