Giter Site home page Giter Site logo

tablesorter's Introduction

tablesorter

Flexible client-side table sorting

Getting started

To use the tablesorter plugin, include the jQuery library and the tablesorter plugin inside the head-tag of your HTML document:

<script type="text/javascript" src="/path/to/jquery-latest.js"></script> 
<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script> 

Tablesorter works on all standard HTML tables. You must include THEAD and TBODY tags:

<table id="myTable" class="tablesorter"> 
<thead> 
<tr> 
    <th>Last Name</th> 
    <th>First Name</th> 
    <th>Email</th> 
    <th>Due</th> 
    <th>Web Site</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
    <td>Smith</td> 
    <td>John</td> 
    <td>[email protected]</td> 
    <td>$50.00</td> 
    <td>http://www.jsmith.com</td> 
</tr> 
<tr> 
    <td>Bach</td> 
    <td>Frank</td> 
    <td>[email protected]</td> 
    <td>$50.00</td> 
    <td>http://www.frank.com</td> 
</tr> 
<tr> 
    <td>Doe</td> 
    <td>Jason</td> 
    <td>[email protected]</td> 
    <td>$100.00</td> 
    <td>http://www.jdoe.com</td> 
</tr> 
<tr> 
    <td>Conway</td> 
    <td>Tim</td> 
    <td>[email protected]</td> 
    <td>$50.00</td> 
    <td>http://www.timconway.com</td> 
</tr> 
</tbody> 
</table> 

Start by telling tablesorter to sort your table when the document is loaded:

$(document).ready(function() 
    { 
        $("#myTable").tablesorter(); 
    } 
); 

Click on the headers and you'll see that your table is now sortable! You can also pass in configuration options when you initialize the table. This tells tablesorter to sort on the first and second column in ascending order.

$(document).ready(function() 
    { 
        $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} ); 
    } 
); 

For DateTime columns you can specify your format, like this:

$(document).ready(function() 
    { 
        $("#myTable").tablesorter( {dateFormat: 'pt'} ); 
    } 
); 

The available ones (currently) are: us, pt and uk. (for pt you can use 'dd/MM/yyyy hh:mm:ss')

tablesorter's People

Contributors

aran112000 avatar bamyers99 avatar christianbach avatar ehershey avatar iajrz avatar iustin avatar jperkelens avatar leosilvadev avatar mottie avatar nubis-icp avatar secondejk avatar tyxla avatar zort avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tablesorter's Issues

Pager with latest jquery version & pager elements

Hi,

I'm just using this tablesorter and everything is worked for me except two things:

  1. The pager: addons/pager/jquery.tablesorter.pager.js does work with latest jquery v1.11 . It only work with the 1.4 or less.
  2. When using pager, it automatic add some attributes to div id pager.

How can I disable this ? The style="top: 617px; position: absolute;" !

Any help is appreciated and thank you so much.

Dynamic column size and count with sticky headers

Hello,
I have been trying to learn this library for 2 weeks. Thanks to good documentation and examples i have done basic requirements for my project easily. But as features gets complicated i have began to struggle.
So here is my problem. I'm using knockout.js for populating the table data. As you can guess column and row counts are dynamic. I'm also trying to achieve resizable columns with sticky headers. Updating row count do not cause any trouble but columns are really painful.

I need to recall something after column count is changed but using $(table).tablesorter() does nothing and sticky header remains unchanged and new columns are not sortable. $(table).trigger("updateall") makes the column sortable and resizable but all column widths goes back to default also my second row inside the header disappears.

This is too much text, I think example may explain it better: http://jsfiddle.net/LkqTU/23729/
+R = add row, -R = remove row, +C = add column -C = remove column
trig = $(table).trigger("updateall"), init =$(table).tablesorter()

Also there is more problems with this demo. Columns are not resizable before right clicking and columns could be shrink into 0 px width.

Using tablesorter with both editable and stickyheaders widgets breaks tab to next cell feature

If you add stickyheaders to a tablesorter instance that is already using the editable widget, you can no longer tab from one editable cell to another. See http://stackoverflow.com/questions/24947995/tab-to-next-cell-in-tablesorter-with-editable-and-stickeyheaders-widgets

On line 604 of jquery.tablesorter.widgets.js, I changed....

This check:

if (event.type === 'filterReset') {
c.$table.find('.' + ts.css.filter).add(wo.filter_$externalFilters).val('');
ts.filter.searching(table, []);
}...

To read:

if (event.which !== 9){
}
else if (event.type === 'filterReset') {
c.$table.find('.' + ts.css.filter).add(wo.filter_$externalFilters).val('');
ts.filter.searching(table, []);
} .....

So far, this seems to fix the tab feature without breaking any of the sorting functionality.

(To be fair this may have some as yet unknown side effect)

Filter ui do not hide when the column is hidden

When hiding one column of a table that is using the filter widget, the filter ui of this column stays on the screen (does not hide with the column) and shifts all the other filter elements on the row (the filter elements are not aligned with the good column).

My English is not really good, so here's an example.
http://jsfiddle.net/cz0Lqzz3/

Displaying the count in the header

Hi
I searched the documentation but couldn't find it. I am using Tablesorter with the Filter widget. I want to know how to display the total number of occurrence of a column item in the column header.

For example,
http://easycaptures.com/fs/uploaded/714/3897489290.png

There are 3 rows with the same name "Boston". When we click on the filter drop down, it should show "Boston (3)" where 3 is the total number of occurrence of "Boston" in the table. The column however may not contain "(3)". How do I achieve this ?

Comma formatted currency doesn't sort.

I've got some values like
$955,555
$933,000,000

And it sorts in that order, even though the second number is larger, but the first number appears larger if you dont count what's after the comma. How do I resolve this?

styles.css distorting table when used with bootstrap

When trying to mix the styles.css file along with bootstrap, the sizing, shading, and effects of the bootstrap classes are grossly distorted. See before and after images below.

Wtihout styles.css:

image

With styles.css:

image

Sorting Non-US centric date format.

Trying to sort a table with date format in the form of dd/mm/yyyy. Any solutions? It seems to treat the date as numbers and sorts them that way!

sorting using locale

Atleast in version 2.0.5b of TableSorter the letters used in scandinavia such as å and ä get sorted the wrong way. The option sortLocaleCompare by default is true, and we have left it to default but this seems to have no effect on the sort order.
order
r.

Doesn't work `lockedOrder` parameter

There is a check for header lockedOrder parameter:

if (checkHeaderOptionsSortingLocked(table, index)) this.order = this.lockedOrder = checkHeaderOptionsSortingLocked(table, index);

and later in the code:

function checkHeaderOptionsSortingLocked(table, i) {
    if ((table.config.headers[i]) && (table.config.headers[i].lockedOrder)) return table.config.headers[i].lockedOrder;
        return false;
}

But if the lockedOrder parameter is equal to 0 (sort descending), function checkHeaderOptionsSortingLocked returns 0 and this.order is not set.
So, there is no possibility to lock descending sort order.

Code example (not working for the first two columns):

$('#mytable').tablesorter({
    headers: { 
        0: {lockedOrder: 0},
        1: {lockedOrder: 0},
        2: {lockedOrder: 1}
    }
});

error when applying tablesorter to a table with no body

if you apply tablesorter to a table with a header row but with no table body, an error occurs in the following line of function buildCache(table), because table.tBodies[0] is not defined.

totalCells = (table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length)...

icon-white unsorted style missing in theme.bootstrap.css

I'm using tablesorter 2.17.1, with the bootstrap theme. I recently updated my tables' headers to be dark blue and tried to pass in the icon-white style to make the sort control icons white. The style is correctly applied, and if I sort ascending or descending the single arrow icon is white. However the default unsorted icon is still black.

I looked at the theme.bootstrap.css and saw the style is missing for the icon-white version. I found the white unsorted image in the images directory and made a base64 string out of it and added a new style to resolve the issue.

To fix the issue you can add this style to /css/theme.bootstrap.css file:

.tablesorter-bootstrapvvhs .icon-white .bootstrap-icon-unsorted {
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAOCAYAAAD5YeaVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAWVJREFUeNqUUL9Lw2AUTGP8mqGlpBQkNeCSRcckEBcHq1jImMElToKuDvpHFMGhU0BQcHBwLji6CE1B4uB/INQsDi4d2jQ/fPeZxo764OV6915f7lLJ81xot9tCURXqdVEUr7IsO6ffH9Q5BlEUCaLwWxWqTcbYnaIoh0Dw4gAvcWlxq1qt9hqNxg6hUGAP+uIPUrGs0qXLer2+v/pTX6QpxLtkc2U2m53ACb8sSdIDXerSEms2m6+DweAICA4d89KGbduf9MpEVdXQ9/2LVqv1CASHjjn3iq/x1xKFfxQPqGnada1W86bT6SiO42OS3qk3KPStLMvbk8nkfjwen/LLuq6blFymMB0KdUPSGhAcOualjX6/f0bCiC7NaWGPQr0BwaFjzn0gYJqmLAiCA8/zni3LmhuGkQPBoWPOPwQeaPIqD4fDruu6L6Zp5kBw6IudchmdJAkLw3DXcZwnIPjy/FuAAQCiqqWWCAFKcwAAAABJRU5ErkJggg==);
}

I haven't checked the other theme css files but they too should probably be checked for this bugs.

thx!
pmolaro

$.browser is deprecated in jQuery 1.9

jquery.tablesorter.js still uses $.browser.msie in it. This property has been deprecated. Please consider rewriting the code using feature detection instead of browser detection.

Chili Missing.

Everyone asks for chili in /docs/, but chili is nowhere to be found.

table names failures

Hi,

This might be a general js thing - tables named with a "." in their ID fail to be sortable:
i.e.

fails while
does not.

Cheers
/Alistair

Custom sort functions

It would be great to have possibility to define custom sort (compare) functions. I'm using tablesorter in my recent app, but table that it sorts contains values that are not sorted correctly by default. I need a way to sort non-ascii characters and bring empty cells down to the end of a table.

Filter Widget search <data-column="all"> doesn't accept capitolized searches

To reproduce:

In the example at http://mottie.github.io/tablesorter/docs/example-widget-filter-any-match.html, search 'A' in the 'First Name' search box. Filtering occurs as expected.

Now search 'A' in the (Match Any Column) box - filtering has removed all rows. Filter the same row with 'a' or 'aa' to see that the filter works correctly with lowercase letters.

I'll have a look at this myself it the issue is still around on the weekend - shouldn't be a difficult fix, but I'm not really good at writing nice idiomatic js.

Nice library, thanks.

Need help with this really weird problems...

Hello Christian Bach, thank you for your ns plugin, but I met a supper weird problem when I tried to implement it...

My code is a little bit long so I will post it if you want to see it later...

Well I followed the instruction, and no matter what I did, it didn't work... the sort arrow just don't show up...
AND, when I check your official site: http://tablesorter.com/docs/ , the demo you have there behave exactly same as my code... the sort arrow don't show up...
HOWEVER, when I check the "unofficial fork": http://mottie.github.io/tablesorter/docs/ , the demo in this page is working... I can click on the sort arrow and sort the table...

I do tested your official site on other people's computer, and it works, the demo has sort arrow and can sort the table...

I'm on Mac OS and tried both chrome and safari... same result...

So I'm wondering... What went wrong...

Tbody sort

Hi.
Is there any solution for tbody sorting?
Not tr, but get information about sorting from tr and sort tbody?
Thank's.

usLongDate handle no space before AM/PM and ignore case

Would you mind changing usLongDate to handle "am", "pm", and not having a space before them?

ts.addParser({
        id: "usLongDate",
        is: function (s) {
            return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s?[APap][mM]))$/));
        }, format: function (s) {
            s = s.replace(/([^\s])([APap][mM])/, "$1 $2");
            return $.tablesorter.formatFloat(new Date(s).getTime());
        }, type: "numeric"
    });

README info

The README says

Start by telling tablesorter to sort your table when the document is loaded:

$(document).ready(function()
{
$("#myTable").tablesorter();
}

Could you be give some guidance where this should be placed in the html file e.g. after or between which tags

Thanks

I have 2 tables. When sorting the first table (table1), it deletes a corresponding row on the second table(table2).

I have table1 and table2. Table1 is the only table I want sorted and is the only table I call to sort $("#table1").tablesorter(); Table1 acts like a draft and the data in trs (except the first td) can be moved from table1 to table2 interchangeably with an add/delete button function in the last td of each tr.

There are hundreds of tr in the tbody with database calls in each td, but I just included 1 for example's sake.

Table1 which tablesorter calls... $("#table1").tablesorter(); in my jquery:

 <div id="TableDiv1" class="tab-pane fade in active">
            <table id="table1" class="tablesorter">
                <thead>
                <tr>
                    <th>TH1</th>
                    <th>TH2</th>
                    <th>TH3</th>
                    <th>TH4</th>
                    <th>TH5</th>
                    <th>TH6</th>
                    <th>Add/Delete</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td class="td1"></td>
                    <td class="td2"></td>
                    <td class="td3"></td>
                    <td class="td4"></td>
                    <td class="td5"></td>
                    <td class="td6"></td>
                    <td class="td7"></td>
                </tr>
                </tbody>
            </table>
        </div>

Table2 example tr:

<table id="table2">
                <thead>
                <tr>
                    <th>TH1</th>
                    <th>TH2</th>
                    <th>TH3</th>
                    <th>TH4</th>
                    <th>TH5</th>
                    <th>TH6</th>
                     <th>Add/Delete</th>
                </tr>
                </thead>
                <tbody>
                    <tr>
                    <td class="td1"></td>
                    <td class="td2"></td>
                    <td class="td3"></td>
                    <td class="td4"></td>
                    <td class="td5"></td>
                    <td class="td6"></td>
                    <td class="td7"></td>
                    </tr>
                    </tbody>
                </table>

The problem I'm having is when a tr has been moved from table1 to table2, and if I then sort table1, it will also move that the tr back to table1 and include it in the sorting. When it does this, it completely deletes the first tr in table2 and skips my add/delete function.

Does the tablesorter take table elements (tbody, ths, tds) of both tables even though I only call it for table1? How can I prevent tablesorter from touching table2?

Update database and refresh on click on a cell

I have the data displaying properly from my database. I have one column that is a boolean and has a checkbox on the grid. This check box is for "completed" column. I would like to click on the check box and call a function in which I can update the database, and then remove that one line from the grid.

Is there some example that shows how to do this?

How to exclude certain rows

Is it possible to use a selector to specify either which rows to INCLUDE for sorting or EXCLUDE? We have some tables where we always want the first row of the table to remain the first row but cant figure out how to make that happen.

Uncaught SyntaxError: Unexpected token <

i tried to figure this one out myself but i'm stuck. As soon as i include tablesorter.js (production and development versions) I'm getting this error:

Resource interpreted as Script but transferred with MIME type text/html: pathToTablesorter.js
Uncaught SyntaxError: Unexpected token <

I researched but i couldn't figure it out. It's defenitely not a problem with my server as 20 other JS files load correctly.

It's included like this
<script src="js/tablesorter.min.js"></script>

If i open tablesorter in eclipse, everything looks fine. If I open it in chrome dev tools, i see my web-page HTML. Maybe i did a stupid mistake somewhere but unless I'm totally blind, the script-tag is fine.

Is tablesorter - by itself without initializing it in javascript - rendering the DOM allready by just being included? Because my tables are created and populated via AJAX and they're not complete on page load (the HTML my be invalid if tablesorter checks the tables on page load automatically).

Sort order lost on pagination

Assume you have a table with 3 columns, "Name","phone","email", if you choose to sort on say email, then go to page 2 it will now be sorted on the default (name) column, the user would be expecting the sort order to not change when changing pages

Sort with nested data

Hello
I have a table with 2 cells, one cell contains an img and the other one different datas.

<tr>
  <td><img src="img.jpg"/></td>
  <td>
    <div class="price-row">Price: <strong>1000</strong></div>
    <div class="year-row">Year: <strong>2001</strong></div>
    <div class="km-row">Km: <strong>10320</strong></div>
  </td>
</tr>

Is there anyway i can instruct this plugin to use certain datas for different sorting?

I need to Sort by Price, Year and Km

Thanks in advance

Problem with sorting mixed (literal+numeric) columns

I've got a problem when i tried to sort my table by a column, which contains mixed types of values: fields that start with letter and fields that start with number.
For example, we have next unordered column:

2
1
3
a
b
c
d

Then when I try to sort it, the sort does not work properly.
ASC:

3
2
1
a
b
c
d

DESC:

a
b
c
d
1
2
3

So as you can see, the order of literal rows has not been changing, whereas order of numbers and their position (above-below letters) is changing correctly.

Table sorting unpredicted behaviour

In my case ,I have two columns (c1,c2)in table.One column(c1) has data while other(c2) has no data in rows.
Step1 - When I click on c1,it sorts rows according to sort order.
Step2 - After this, I click on column c2,it sorts rows even though it has no data .
Ideally it should not sort the rows having no data?
Is this an issue or designed in this way only?

Definition of "ascending" and "descending" backwards?

I'm using tablesorter in a Rails project, and an issue was brought to light when I was trying to capture sort order from a tablesorter table on the page and use that in an ActiveRecord collection order statement.

A different CSS class is applied to a column depending on if it's sorted "ascending" or "descending". According to the demo on the tablesorter homepage, "descending" means A-Z, 0-9. However this isn't what I was under the assumption of, and it's not how ActiveRecord defines "ascending" vs "descending" either.

tablesorter1

Here you can see that the "descending" class is applied to the First Name column. By my definition this should result in Z-A sorting. However, the result is this:

tablesorter2

I noticed this issue hadn't been brought up before, so I wonder if there's something I'm missing here. Anyone care to shed some light on the situation?

Enabling tablesorter disable thead inputs events

I have a table with checkbox on thead and everytime i enable tablesorter all the events attached into that checkbox stop working!

It's like i never attached anything, no errors, nothing...

Here's how i enable the tablesorter:

$(".table").tablesorter({ dateFormat: "ddmmyyyy" });

If i comment this line the checkbox events start working again!

Arrows on the last line of the header

To sort 1-character columns, the arrows should be in an extra row of the header.
Here is a patch that does that.

16c21
< table.tablesorter thead tr .header {

---
> table.tablesorter thead tr:last-child  .header {
31c36
< table.tablesorter thead tr .headerSortUp {

---
> table.tablesorter thead tr:last-child .headerSortUp {
34c39
< table.tablesorter thead tr .headerSortDown {

---
> table.tablesorter thead tr:last-child .headerSortDown {

Table head <th> cell not receiving sorting class

One of my table headers is not receiving the headerSortDown or headerSortUp class. The sorting function works and the "header" class is applied when initialized but the header class is not updated when sorted. Other headers in my table do receive the class. I can't seem to figure out what is causing the issue with that specific column.

Column Resize doesnt work with many columns

I have about 30 columns that scroll off the browser. I can use the scroll bar to see the other columns.

Resizer doesnt resize the columns or let me set a fixed starting width.

If I cut back the columns so they fit on the browser then it works great.

Any ideas what I need to change?

this is the definition of the table:

Table sorter adds rows when sorting after post

I have a web app that uses table sorter. If I perform search #1 (filling a form and posting to refill rows w/ ajax) and then perform search #2 (a new search, posting for new rows w/ ajax) and then click a column header to sort the rows -- then after sorting, some of the rows from search #1 re appear in the table! I think javascript has stored these rows some how and refills them after search.

javascript error when applying both sortList and headers options

When you apply both the sortList and headers options, you get an error right after the page loads.

When you add the sortList option, if I remember correctly, the form sorts itself once the page is loaded. When you add the headers option, you decide which of the colums are sortable.

When you add them both, and set it up so that the list is sorted on some of the unsortable columns specified in headers, you get an Cannot read property 'addClass' of undefined error. This error stems from a rather weird implementation in the setHeadersCss method.

Hope you can fix this somehow :)

Bad documentation comments

These comments seem wrong:

 * @option Object headers (optional) An array containing the forces sorting
 *         rules. This option let's you specify a default sorting rule. Default
 *         value: null
 * 
 * @option Array sortList (optional) An array containing the forces sorting
 *         rules. This option let's you specify a default sorting rule. Default
 *         value: null

also

 * @option Array sortAppend (optional) An array containing forced sorting rules.
 *         This option let's you specify a default sorting rule, which is
 *         appended to user-selected rules. Default value: null

They talk about "forced sorting rules", which doesn't match the option names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.