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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:13:59+00:00 2026-05-19T04:13:59+00:00

I have a table in database that has 2 columns Name | Age, I

  • 0

I have a table in database that has 2 columns Name | Age, I display it in a HTML page.

I want to sort the table in HTML page based on a field when the user clicks on it.

I have a PHP function to do the sorting based on a field.

But after obtaining the rows in sorted order in PHP, I’m looking for ways by which I can update the HTML table without navigating away from the page.

  • 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-19T04:13:59+00:00Added an answer on May 19, 2026 at 4:13 am

    You can do sorting in javascript, without having to communicate with the server. For example, this code will sort a table based on the content of the Nth column:

    function sortTable(table, column, skipHeader) {
      // Stick each row into an array.
      var rows = [];
      for (var i = skipHeader ? 1 : 0; i < table.rows.length; i++) {
        rows.push(table.rows[i]);
      }
    
      // Sort the array based on the innerText of the column'th cell in each row
      rows.sort(function(a, b){ 
        a = a.cells[column].innerText;
        b = b.cells[column].innerText;
        return a < b ? -1 : (b < a ? 1 : 0);
      });
    
      // Re-order the rows by removing/appending in the sort order
      for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        var container = row.parentElement;
        container.removeChild(row);
        container.appendChild(row);
      }
    }
    

    For example, to sort the first table in the document, on the first column, and skip the header row:

    sortTable(document.getElementsByTagName('table')[0], 0, true);
    

    Obviously you’ll want to modify this to suit your own tastes, especially the sorting, but it’s a lot simpler than having to post the data back to the server, which I think is what you’re proposing.

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

Sidebar

Related Questions

I have a Database table that I want to display in a DataGridView. However,
Suppose I have a database table that has a timedate column of the last
I have a user table in my mysql database that has a password column.
I have a database structure that has a Person table which contains fields such
I have a database table that i want to allow my friends to update.
I inherited a mysql database that has a table with columns like this: object_id,
I have a table within my database that has many records, some records share
I have to write a query to database, that has such table: TABLE HISTORY:
I have a table in the database that I'm retrieving using LINQ to SQL,
I have a table in a database that represents dates textually (i.e. 2008-11-09) and

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.