Table Sorter

This updated table sorter script is easy to use and feature packed at only 2.5KB. New features include column highlighting, optional pagination, support for links, and date/link parsing. A few other features are alternate row highlighting, header class toggling, auto data type recognition and selective column sorting. More updates will follow soon.

To initialize a table sorter follow the pattern below:

var sorter = new TINY.table.sorter('sorter');
sorter.head = 'head'; //header class name
sorter.asc = 'asc'; //ascending header class name
sorter.desc = 'desc'; //descending header class name
sorter.even = 'evenrow'; //even row class name
sorter.odd = 'oddrow'; //odd row class name
sorter.evensel = 'evenselected'; //selected column even class
sorter.oddsel = 'oddselected'; //selected column odd class
sorter.paginate = true (false); //toggle for pagination logic
sorter.pagesize = 15 (20); //toggle for pagination logic
sorter.currentid = 'currentpage'; //current page id
sorter.limitid = 'pagelimit'; //page limit id
sorter.init('table',1);

Before initialization, a new table sorter object must be created. The parameter taken by TINY.table.sorter is the variable name used for the object. The object.init function takes 2 parameters: the id of the table and the initially sorted column index (optional). If you want to exclude a column from sorting add class=”nosort” to the appropriate table header. Table styling is completely customizable via the CSS.

This script has been tested in all major browsers and is available free of charge for both personal or commercial projects under the creative commons license. Community support is available here. Paid support is also available, contact me for details.

Click here for the demo.

Click here to download the source code.

Posted by Michael in JavaScript on March 7, 2009

201 Responses

I’m using firefox with the Noscript plugin. I can turn Javascript support off in the click of a button, and I noticed that when viewing your demo without Javascript active, only 50 of the 100 entries were in there.

Now, a browser without Javascript these days is about as common as air on the moon, but wouldn’t it be better if the full 100 were visible when Javascript isn’t active?

Koen on March 08, 2009 at 7:48 am

@Koen – There are only 50 entries.

Michael on March 08, 2009 at 7:53 am

I’m using tablesorter(plugin) with jquery. But this looks awesome only 2,5kb! Maybe for the next version of my product I will consider using this library. Thanks

Vladimir on March 08, 2009 at 11:26 am

Awesome! :D Thank you! :)

Edwin on March 08, 2009 at 2:45 pm

Hey

wil you incorperate a search feature in the future?

Frederik on March 08, 2009 at 3:45 pm

@Frederik – Absolutely, it is already in the works.

Michael on March 08, 2009 at 5:17 pm

It looks great… when is the jQuery version ready? :P

ShaggyStyle on March 08, 2009 at 8:01 pm

Great work on this, Michael! Thanks for sharing!

EricB on March 09, 2009 at 12:11 am

Amazing script. It would be cool to have this combined with Ajax support, because there are lot of admins with huge number of data. e.g. 10.000 items in DB table.

Csaba on March 09, 2009 at 2:22 am

Great! Superbe! Prima (de)! Ganzissima (it)!

Federico Grilli on March 09, 2009 at 2:48 am

Hi nice little script

please tell me that isn’t real data in the demo tho!

edmondscommerce on March 09, 2009 at 4:13 am

wow, just some time back i was searching for a similar script on google and suddenly i happened to check delicious… an here i am…..

thanks michael, thanks delicious :)

WebDesigner on March 09, 2009 at 5:44 am

@Csaba – AJAX support will be part of the next release along with search and a couple other options.

@edmondscommerce – No, of course it is not real information. I used a random data generator.

Michael on March 09, 2009 at 7:22 am

This plugin has any domentation? Thanks for share!

Sanbor on March 09, 2009 at 8:29 am

great sortable for tables.

internationalization for sorting would be nice for future versions.

volkan on March 09, 2009 at 10:16 am

haven’t look detail yet, but demo looks great!!bookmarked and subscribed for updates.

winmonaye on March 09, 2009 at 2:02 pm

I notice you use a background image for the arrows and then CSS to rotate between ascending and descending. Any chance you can code in a textual equivalent for JAWS users that also rotated between the words “Ascending” and “Descending”? You can even make the words invisible by wrapping them in CSS that moved them off the screen (left: -5000px; position: absolute;). This way your table (which is great!) would be accessible to all users, not just visual users. :)
C

chad on March 09, 2009 at 10:11 pm

Awesome! This looks great, I can’t wait to try it out!
This post is will definately be bookmarked

Badnmad WebDev on March 10, 2009 at 1:59 am

for info the initial pagination logic parameter is sorter.pagesize instead of sorter.pagsize
therefore you can have the good initial value :)

Laurent on March 10, 2009 at 7:19 am

@Sanbor – More complete documentation will be available when Scriptiny launches.

@volkan – Thank you for the suggestion, it is now on my list.

@Laurent – Thanks for the catch, I have updated the post.

Michael on March 10, 2009 at 7:43 am

How about table filtering based on column values? For instance, instead of search, you might support selection of data based on a value picked from a dropdown list (prebuilt filter of unique values from one of the columns). it seems like filters are gaining in popularity.

Nice tool!

Deb Fahey on March 10, 2009 at 11:08 am

How many table rows do you think it can handle before it would fall over or load very slowly?

Derek Organ on March 10, 2009 at 12:03 pm

@Deb – Thanks for the suggestion, I will keep that in mind for the next version.

@Derek – It really depends on a few factors… the speed of the client computer, the browser type and version, the complexity of the table, etc. In most scenarios I would not exceed a couple hundred hundred rows. Past that point it would make more sense to go server-side/AJAX.

Michael on March 10, 2009 at 12:37 pm

I just wan’t to say thanks a lot :) .. this is very useful for my current project .

scalar on March 10, 2009 at 10:55 pm

I tried out your script and I do like it, I actually have 8 different instances on the same page. One thing I notice is that it does not sort Date correctly in the (yyyy-mm-dd) format due to it sorting the numbers up to the – marks for each part.

sample of the data sorted asc:
2006-05-31
2008-10-08
2008-09-10
2008-10-27
2009-01-10

Any idea how to fix it?

zoggy on March 12, 2009 at 2:23 am

@zoggy – The Date.parse method does not accept the format in your example to convert into date objects. You could add the logic in the cp function to replace dashes but I am reluctant to add anything else in the function to try and keep the processing time down. I will take a look at it and do some testing.

Michael on March 12, 2009 at 7:40 am

I searched around for sorting using javascript in the SQL date format (YYYY-MM-DD hh:mm:ss) where the time part is optional and I stumbled across:

myParseDate = function (oData) {
if (oData === undefined) return oData;
var parts = oData.split(‘ ‘);
var datePart = parts[0].split(‘-’);
if (parts.length > 1) {
var timePart = parts[1].split(‘:’);
return new
Date(datePart[0],datePart[1]-1,datePart[2],timePart[0],timePart[1],timePart[2]);
} else {
return new Date(datePart[0],datePart[1]-1,datePart[2]);
}
};

Hope this helps anyone else that ran into my issue.

zoggy on March 12, 2009 at 10:40 pm

Nice script. Not sure if I’m doing something wrong, but for some reason the nosort column feature does not work in column 2. I can add the class=”nosort” to any other column. Keep up the good work!

John on March 13, 2009 at 9:34 am

Everything works fine, except the “entries per page” selector. It should reset itself on page reload. For eg: if I choose to display 5 records, and next time I refresh the page, it’d display all the records, but the selector continues to display 5.

Website Development on March 14, 2009 at 12:45 pm

I keep getting “sorter is not defined : line 18″ from script.js , any ideas? The only thing potentially “weird” about how I am using your script is it is on a table that gets generated from an AJAX request. That said I am using the table structure from the example almost exactly.(same class name and id)

Carl on March 14, 2009 at 2:16 pm

Great work!.
I’ve just created my own grid using jquery and some native javascript, but maybe it will be replaced by this one. But when do you plan to support ajax json? a possible day? I’ve implemented it in my own grid, it’s quite simple.

Rasmus Christensen on March 15, 2009 at 2:02 pm

@Vladimir, it’s not a library it’s plain javascript and stop using js libraries: THEY SUCK

carlos on March 16, 2009 at 12:34 pm

This is fantastic. I am trying to add a table that is very wide (horizontal) with lots of columns. I would like to be able to have a horizontal scroll bar with this. Any idea how I might manipulate things to accomodate?

Thanks!

Gary on March 16, 2009 at 8:05 pm

great work once again

i miss one thing though, especially when dealing with dates you often want the default sorting to be in reverse order, is there a way to do this?
could be done by adding a “reverse” class to the header?

also, when adding a second class on the header apart from “nosort” (say for styling purposes) the element is no longer treated as nosort

Dimitris on March 18, 2009 at 6:22 am

How do you implement this to sort multiple tables on teh same page ?

Sean Clarke on March 19, 2009 at 7:29 am

Amazing script! Is it possible to put the default sorting of a field containing date AND time in reverse order? For example: 19-03-2009 00:51:13 (DD-MM-YYYY HH:MM:SS). Can’t figure that one out…

Keep up the good work, Michael.

Karel on March 19, 2009 at 9:08 am

If anyone comes across my above issue with ajax, I fixed it by simply removing the var from
“var sorter = new TINY.table.sorter(“sorter”);”
now reads
“sorter = new TINY.table.sorter(“sorter”);”

Carl on March 19, 2009 at 3:58 pm

How do you implement this to sort multiple tables on teh same page ?

Como implemento para multiples Tablas

<script type=”text/javascript”>
var sorter = new TINY.table.sorter(“sorter”);
sorter.head = “head”; //header class name
sorter.asc = “asc”; //ascending header class name
sorter.desc = “desc”; //descending header class name
sorter.even = “evenrow”; //even row class name
sorter.odd = “oddrow”; //odd row class name
sorter.evensel = “evenselected”; //selected column even class
sorter.oddsel = “oddselected”; //selected column odd class
sorter.paginate = true (false); //toggle for pagination logic
sorter.pagesize = 15 (20); //toggle for pagination logic
sorter.currentid = “currentpage”; //current page id
sorter.limitid = “pagelimit”; //page limit id
sorter.init(“lunes”,2);
sorter.init(“martes”,2);
sorter.init(“miercoles”,2);
sorter.init(“jueves”,2);
sorter.init(“viernes”,2);
</script>

angiedelgado on March 19, 2009 at 5:34 pm

I tried the tip from angiedelgado to get multiple tables working on one page, labeled the tables with id=”table1,2,…” and added sorter.init(”table1,2…”,1) but now nothing is sortable. anyone can help?

Chris on March 19, 2009 at 7:24 pm

This looks like a nice way to sort a table. Very lightweight also. I think I am going to test it this weekend thanks!

Evan on March 20, 2009 at 7:21 am

I would like to make a mouseover background-color on the rows, how is that possible?

Thomas Jensen on March 22, 2009 at 2:38 pm

I really like what you have done.

Since I can’t see any documentation, is there a way to open to a specific page? The problem is that I have a link in each row to go to a detail page, and after going to the detail, having a way back to the specific page that the link was on.

Websfear on March 24, 2009 at 8:56 am

Thank you very much for this useful table sorter!

I am having trouble getting the table to start out with a specific row sorted in descending order. I added class=”desc” to the header row for the column I want to sort descending, but it doesn’t work. When the object is init’ed, the DOM is modified and the class=”desc” is dropped and changed to class=”head” instead. Any ideas?

Thanks.

upandbeyond on March 25, 2009 at 1:17 am

Hi Michael,

Nice little script you got. Just want to ask a question or two.
Do you have the unpacked version available? I would love to see it.

Also, how soon would multi-lingual support become available? Especially, in my case, for asian characters?

Your help is much appreciated.

Sky on March 26, 2009 at 12:35 am

Opp’s
** When I say unpacked version, I mean the version with the full variable names and possibly notes you might have written***

Sky on March 26, 2009 at 12:37 am

Specific page update…

Well I did figure out a way of dooing it, but it isn’t very elegant.

I placed a for loop in my onload function to repeatedly call sorter.move(i);

I would have been nicer if the move function took anything other than -1 an 1.

websphere on March 26, 2009 at 9:25 am

Great script !
Sadly it does not sort dates correctly in the dd/mm/yyyy format.

Sample output:
13/01/1962
03/08/1963
27/11/1961
19/08/1962
31/12/1961
10/08/1963

Thanks for sharing !

jorge torres on March 27, 2009 at 4:20 pm

That’s a pretty nice script I use now for my projects. But i’ve got a problem. How do you sort a column descading at initialization?
class=”desc”

thx for help

exer on March 28, 2009 at 6:35 am

Thank you for thisd very nice script, I use it on my site.

To make a mouseover background-color (and color) on the rows, you can use the css:

.sortable tr:hover {background-color: #99F; color:black;}
.sortable tr:hover td {background-color: #99F; color:black;}

Jean Eloy on March 31, 2009 at 8:11 am

This script is great. I would love to use it in some projects but the fact that you can’t specify a date format on a column is a show-stopper. Dates aren’t always in the format of MM/dd/yyyy.

Thanks for the script though…your work is appreciated.

Lee on April 01, 2009 at 1:16 pm

To make this script work with the YYYY-MM-DD format (mysql date) just change these line in the script.js which is in the cp function.

From:
i=Date.parse(f); n=Date.parse(c);
To:
i=f.replace(/-/g,”); n=c.replace(/-/g,”);

enjoy!

zoggy on April 03, 2009 at 4:35 am

How could this be altered to sort in descending order rather than ascending upon initialization?

Lance on April 03, 2009 at 2:33 pm

in case anyone ran into my situation with needing items that start with _ to be sorted above numerical (0-9) items here you go.

example data: 300 , _test , test2 , test
would sort to become: _test, 300, test, test2

in the cp function, right above ‘return g>h?1:(g<h?-1:0)’ add:
if(i.match(/_/)) { g=g.replace(/_/,’!'); }
if(n.match(/_/)) { h=h.replace(/_/,’!'); }

What this does is replace the first _ found in the string with ! which comes before 0 in sorting. I’m sure there is a better fix but this works just fine.

zoggy on April 03, 2009 at 9:15 pm

thanks for this Excelent script but,
How can I implement multiples tables in the same page?

Claudia on April 04, 2009 at 12:15 pm

Hi is there a new version coming out? I ask because I’m about to use this table for a user mail system and wanted to know before I started writing the code

acctman on April 04, 2009 at 1:13 pm

I really like that script. It is really efficient and simple.
But is there away to use multiple tables on one page?
If not it would be a great addition for next version I think. thx

John on April 04, 2009 at 6:04 pm

Hi, with the sorter option selected at 10 on page load and when click to go to the next page (arrow at bottom) and then click a link in the next page, when I click the BACK button in IE 7 the page loads with it’s initial 10, not where I left off in the next page. Is there a way to keep it at the last page? FireFox this works okay.

Tony on April 06, 2009 at 12:53 pm

there seems to be a problem when having the script display anything other than 20 per page. if you set <option value=”10″ selected=”selected”>10</option> it still shows 20 when the page is loaded.

acctman on April 07, 2009 at 11:41 am

@Claudia and John – Multiple tables on the same page.

in the javascript script section where you define your table id and var just make it unique, example of 2 tables that I have on the same page:

var sorter1 = new TINY.table.sorter(“sorter1″);
sorter1.head = “head”;
sorter1.asc = “asc”;
sorter1.desc = “desc”;
sorter1.even = “evenrow”;
sorter1.odd = “oddrow”;
sorter1.evensel = “evenselected”;
sorter1.oddsel = “oddselected”;
sorter1.paginate = false;
sorter1.init(“table1″,1);

var sorter2 = new TINY.table.sorter(“sorter2″);
sorter2.head = “head”;
sorter2.asc = “asc”;
sorter2.desc = “desc”;
sorter2.even = “evenrow”;
sorter2.odd = “oddrow”;
sorter2.evensel = “evenselected”;
sorter2.oddsel = “oddselected”;
sorter2.paginate = false;
sorter2.init(“table2″,1);

just make sure you have id=”table1″ for one table, and id=”table2″ for the next.. enjoy!

zoggy on April 08, 2009 at 11:55 pm

Даже друзьям разослал ссылку на эту запись!

Протасов on April 09, 2009 at 5:32 am

how to set default selected table head.And then if after last page how to disable achor tag

alaguraja on April 09, 2009 at 9:12 am

First off, awesome script!

I don’t know if this is a bug but when using both these scripts, they will both work initially. But when you click a sortable column, clueTip loses it’s functionality. This surprisingly doesn’t happen in IE6 but Chrome and Firefox. Is there a way to keep clueTip’s functionality even after sorting and switching pages and page sizes?

mojaam on April 11, 2009 at 11:37 am

VERY NICE, yet small script. Got one question

How To Start A Table With Sorting In A Certain Column? supposed, i want to start “desc” in sortable column B. How to do that?

liverpool on April 12, 2009 at 10:12 pm

sorter.init(”table2″,2);

websphere on April 14, 2009 at 9:31 am

thank you. WebSphere. It works

liverpool on April 14, 2009 at 10:23 am

@Carl on 19 Mar 2009 at 3:58 pm

Many thanks for posting that, fixed my very similar AJAXy problem.

S.

Simon on April 15, 2009 at 10:26 am

hello, i’m currently trying to design my website using joomla 1.5, i downloaded sorter.zip but don’t know how to build a sortable table in one of the article. Can anybody please help??.. I tried to copy and paste the html code in the sample page to my article, but it doesn’t work.

henky on April 15, 2009 at 11:28 pm

To add sorting by desc, just add

sorter.sortmethod = “desc”;

and change line 18 to
if(f!=null){var a=new Function(this.n+’.wk(‘+f+’)'); a(); if(this.sortmethod.toLowerCase() == “desc”){a();}}

Better and leaner than tablesorter.com Although I like the multiple column sorting tablesorter does.

Rick St Jean on April 17, 2009 at 12:15 pm

I use your script in combination with Thickbox. So I have one column with links which should open in a thickbox window. The problem is now: as soon as I sort the table any other than the default way, the thickbox doesn’t work anymore, so the link is just opened in a new window.
Any idea how to fix this?

Lukas on April 21, 2009 at 3:05 am

How can you format the date as dd-mmm-yyyy and make it sort correctly?

Jay on April 22, 2009 at 8:15 am

Is someone can explain me how to use this script with awstats. I need to sort columns, i tried many things like this one, but without results :( http://www.frequency-decoder.com/2006/09/16/unobtrusive-table-sort-script-revisited

i use firefox or safari, but i can’t see sortables possibilities.

Is TinyTable javascript can help me? Is there any tuto | how to ?
Thanks

alfageek on April 26, 2009 at 10:52 am

Thank you very much :) As many of the above comment authors I also like to use JavaScript libraries, but this is the second or maybe third occasion I found your solution when searching for lightweight scripts, so this time I dugg this post to make sure I won’t forget about it :)

Webdev on April 26, 2009 at 2:22 pm

Fantastic script!
How print te entire table?
(disable pagination in media=”print”)
Thanks

Feli on April 28, 2009 at 5:47 am

:::::::::::: Sugestion for disable pagination in media=”print”:::::::::::::::

– Change the —————–
1.- <tr class=”evenrow” style=”display: none;”>
2.- <tr class=”oddrow” style=”display: none;”>

3.- t.a[i].o=i; var v=t.r[i].cells[y]; t.r[i].style.display=”;
4.- for(i;i<this.l;i++){t.r[i].style.display=i>=s&&i<l?”:’none’}

–With ——————-

+<style type=”text/css”>
+ .rowhidden {
+ display:none
+ }
+ @media print {
+ .rowhidden { display: }
+ }
+ @media screen {
+ .rowhidden { display:none}
+ }
+</style>

1.- <tr class=”evenrow rowhidden” >
2.- <tr class=”oddrow rowhidden” >

+function addClass(element, value) {
+function removeClass(element, value) {

3.- t.a[i].o=i; var v=t.r[i].cells[y]; removeClass( t.r[i], ‘rowhidden’ );
4.- for(i;i<this.l;i++){ addClass( t.r[i], ‘rowhidden’ }

Its a solution?

Feli on April 28, 2009 at 6:21 am

The person in charge of this website needs to have their head examined. I clicked on the prompt above that reads “click here for a demo” and I got a folder list. Now, it wold be OK if it was a list of different demos, bu it’s not. It’s an email tag that opens your email client. What a joke? What kind of idiot is responsible for this nonsense?

Andre on April 29, 2009 at 5:27 am

I like this a lot. I’ve only got two comments – when I use it none of the gif images in the table head work for some reason. Also it displays all the table entries even if you tell it to show only ten. Any solutions?

James Chalmers on April 29, 2009 at 9:37 am

Hi … Nice Script ..

Anyone with a solution to sort date in format dd/mm/yyyy ?

samdhal on May 04, 2009 at 12:08 am

Thanks a lot, saved me a bit of time

(Twittering mode) I just found this, ad video about development process, quite funnny actually : http://www.youtube.com/watch?v=IlFL-uJ4hmw

Paul on May 08, 2009 at 4:46 pm

i like the speed of this compared to some of the ajax.net stuff.

burnley web developer on May 18, 2009 at 6:07 am

For sort the german date replace this

//i=Date.parse(f); n=Date.parse(c);

with this

i=f.replace(/./g,”); n=c.replace(/./g,”);

René on May 19, 2009 at 2:21 am

Hm..sorry René but it doesn’t work for me

Lukas on May 19, 2009 at 6:06 am

How to make column initial sorting descending ?
Thanks for your good work !

c3essam on May 24, 2009 at 12:13 pm

Does anyone know how to make the navigation controls at the bottom of the table also appear at the top?

That is the controls should be both @ the top and bottom of the page.

FYI, just copying <div id=”controls”> section to the top of the grid does not work 100% (it does not display the paging text properly – “page x of y”)

mrLami on May 27, 2009 at 7:56 am

OK HERE IS HOW TO MAKE THE SORTING TO DESC

===============================================
1ST Change:

sorter.init(“table”, 0);

COMMENT: 0 IS THE ROW id COLUMN BECAUSE I WANT TO SORT THE id BY DESCENDING. YOU CAN PUT ANY NUMBER ACCORDINGLY TO YOUR COLUMN. SO 0 IS THE 1ST COLUMN.

=============================================
2nd Change:
IN script.js EDIT THIS LINE 29

if(t.p==y){t.a.reverse(); x.className=t.d?this.asc:this.desc; t.d=t.d?0:1}

TO

if(t.p!=y){t.a.reverse(); x.className=t.d?this.asc:this.desc; t.d=t.d?0:1}

THEN SAVE THE JS AND START PAGE.

THERE YOU GO. YOU JUST DONE THE DESC ORDER.

MAIL ME IF STIL GOT PROBLEM. TQ
izzuddinmeister@gmail.com

Izzuddin Noor on May 28, 2009 at 9:54 pm

MR LAMI. MAIL ME FOR THE CODE I MANAGE TO PUT THE CONTROL ON THE TOP PAGE. THANKS. BUT HERE HOW IT GOES IF HTML.

TRICKS : CREATE NEW TABLE WHICH SHARE THE SAME CLASS=”sortable”.
SO BY THAT MEAN WE GOT 2 TABLE INSTEAD OF 1. AND REMOVE THE CONTROL AT THE BOTTOM PAGE. BECAUSE IT WILL CRASH THE PAGING AND ENTRIES VIEW.

============================================
<table cellpadding=”0″ cellspacing=”0″ border=”0″ id=”table1″ class=”sortable” width=”998px;”>
<tr>
<td>
<!– TOP: BEGIN Paging And Sorting –>
<div id=”controls”>
<div id=”perpage”>
<select onchange=”sorter.size(this.value)”>
<option value=”5″>5</option>
<option value=”10″ selected=”selected”>10</option>
<option value=”20″>20</option>
<option value=”50″>50</option>
<option value=”100″>100</option>
</select>
<span>Entries Per Page</span>
</div>
<div id=”navigation”>
<img src=”images/first.gif” width=”16″ height=”16″ alt=”First Page” onclick=”sorter.move(-1,true)” />
<img src=”images/previous.gif” width=”16″ height=”16″ alt=”First Page” onclick=”sorter.move(-1)” />
<img src=”images/next.gif” width=”16″ height=”16″ alt=”First Page” onclick=”sorter.move(1)” />
<img src=”images/last.gif” width=”16″ height=”16″ alt=”Last Page” onclick=”sorter.move(1,true)” />
</div>
<div id=”text”>Displaying Page <span id=”currentpage”></span> of <span id=”pagelimit”></span></div>
</div>
<!– TOP: END Paging And Sorting –>
</td>
</tr>
</table>
<table cellpadding=”0″ cellspacing=”0″ border=”0″ id=”table1″ class=”sortable” width=”998px;”>
<!– HERE IS THE NORMAL PAGE –>
</table>
============================================

Izzuddin Noor on May 28, 2009 at 9:59 pm

Great, small code! Thanks. If one makes table boxes editable, and adds link to write in more rows, as needed, would this make your sorting code a simple spreadsheet? (It would have all the basic functions I need to work with most web data).

thakns,
Greg

Greg on May 29, 2009 at 2:39 am

Hi Michael, code is useful and excellent. Thanks!

HackeR FrienD on May 29, 2009 at 10:36 pm

I’m having the same issue mojaam and lukas had. When I use tinytable with another script like thickbox or something, it works fine at first, even after paging.

BUT AFTER SORTING THE TABLE, it breaks. Has anyone been able to figure out why it’s breaking stuff after a sort?

mrLami on June 02, 2009 at 4:12 pm

your code is simplier than what i’ve found….great code…

I’ve tried experimenting your code, i’ve put some null values on the table,
works well but how about not to sort null values on the table, should it be better if all null cell will appear on the bottom of the table?…

fern on June 08, 2009 at 3:17 am

wow..i guess i should redesign my tables using this as a source code..

thanks a lot!

mrMartin on June 11, 2009 at 10:42 pm

great work, thanks for sharing
is there a way to destroy the sorter manually? (ie in case one wants to print the full table after sorting the table)

dimitris on June 12, 2009 at 1:05 pm

Ok i notice you updated with new version of table sorter. can you explain me abit wht are the changelog that had been made, before im upgrading to new sorter. Thanks Dude.

Izzuddin Noor on June 15, 2009 at 2:22 am

very cool script. Is a version which uses ajax paging/sorting on the cards as this always becomes an issue?

lofty on June 24, 2009 at 2:14 pm

@lofty -why the hell wont you read instead of asking question which has been asked (and answered (yes) many times before??)

Nice script. I wouldnt add too much to it, otherwise it just becomes big and you can never match ALL the features of the big boys
- In any event, AJAX retrieval may be overkill, why? because you can always issue another query and make it granular enough so that the resulting dataset fits within the reasonable 200 item limit.

I am trying to get this to work on mobile device with some success :) will keep you posted -thanks for your work in this and other tiny,useful scripts! ( Like a mouse's penis, it may be small, but it gets the job done!- and who doesnt need more mice?? )

steve on June 24, 2009 at 6:35 pm

In case no second arg is specified in init(), this line:

for(i=0;i<this.l;i++){t.a[i]={}}

Needs to be changed to:

for(i=0;i<this.l;i++){t.a[i]={}; t.r[i].className=i%2==0?this.even:this.odd;}

So that rows get formatted correctly with even/odd

Wendtly on June 25, 2009 at 4:36 pm

Print friendly implementation in my spanish blog "http://weblogs.javahispano.org/feli/entry/sort_table_printfriendly".

feli on June 28, 2009 at 4:29 pm

How to make the sorting function in Descending Order
—————————————————————–

Find this code:

return g>h?1:(g<h?-1:0)

Replace with this Code:

return g<h?1:(g>h?-1:0)

William on June 29, 2009 at 10:51 am

@ William
I William I've made this change but don't work. The sorting is alwais ascendent. Are there any other changed to do in the code?
Thanx

Giovanni on June 30, 2009 at 7:52 am

I've found this script by chance and thought great! I was doing a ReportMaker(Grelo) with php and not found any easy-to-use solution without ajax. And it was like a glove (brazilian slang). Thank you so much! When I launch my first version I tell you and don't thought that I'll not disclose your scipt. I'll write all your rights.

Rodrego on June 30, 2009 at 12:01 pm

OK THIS IS THE EXAMPLE FOR DESC ORDER. I HAVE UPLOAD THOSE FILES. AND PLEASE GIVE CREDIT TO ORIGINAL AUTHOR. MR. LEIGEBER.
I MADE SOME MODIFICATION ON THE SCRIPT.JS AND ADDED NEW VARIABLE FOR TELLING JAVASCRIPT TO RENDER IT DESCENDING ORDER.

DOWNLOAD LINK : http://www.mediafire.com/?im5xmoznvwm

GREAT JOB MR. LEIGEBER LOVES UR WORKS.

Izzuddin Noor @ DESC METHOD on July 02, 2009 at 3:15 am

I tried this on an old table and it works great even with 4000 rows! Very good!

Michael House on July 09, 2009 at 1:51 pm

I use this on Firefox is ok…
but use this script on IE is not run sort…
Plase Help me…and…tell me… thanks!!!

poxcoo on July 09, 2009 at 8:10 pm

To make this script work with the "YYYY-MM-DD hh:mm" format just change these line in the script.js which is in the cp() function.

From:
i=Date.parse(f); n=Date.parse(c);
To:
i=Date.parse(f.replace(/\-/g,'/')); n=Date.parse(c.replace(/\-/g,'/'));

enjoy!

feli on July 10, 2009 at 4:28 am

I needed to have certain rows with specific styles depending on the data in them, but when the table fires up it kills all classes you have in there. In order to get your own classes to persist add in place of this line
r.className=i%2==0?this.even:this.odd; var cells=T$$('td',r);

the following
var oldClasses = t.r[t.a[i].o].className.replace(this.odd,'').replace(this.even,'');
r.className=i%2==0?this.even + ' ' + oldClasses:this.odd + ' ' + oldClasses; var cells=T$$('td',r);

lofty on July 10, 2009 at 6:21 am

thanks feli …. i trying..change script.js

From:
i=Date.parse(f); n=Date.parse(c);
To:
i=Date.parse(f.replace(/\-/g,'/')); n=Date.parse(c.replace(/\-/g,'/'));

but…. is not runing sorting…. so sad…!!

poxcoo on July 11, 2009 at 2:58 am

Hi there. Any idea why I cannot use TinyBox and TinyTable on the same page? Only the script i load last works.

Vikram on July 25, 2009 at 5:57 am

Hola, he logrado ordenar las fechas en formato dd/mm/aaaa, capaz que haya alguna otra forma, pero esta funciona bien!.
Hi, I have the solution to order dates in dd/mm/aaaa format:

—- remplazar: – replace this:

var g,h; f=g=f.v.toLowerCase(), c=h=c.v.toLowerCase();
var i=parseFloat(f.replace(/(\$|\,)/g,'')), n=parseFloat(c.replace(/(\$|\,)/g,''));
if(!isNaN(i)&&!isNaN(n)){g=i,h=n}
i=Date.parse(f); n=Date.parse(c);
if(!isNaN(i)&&!isNaN(n)){g=i; h=n}
return g>h?1:(g<h?-1:0)

—- por: – for this:

var dX,mX,aX,fX,dY,mY,aY,fY,pos,pos2;
var g,h; f=g=f.v.toLowerCase(), c=h=c.v.toLowerCase();
var i=parseFloat(f.replace(/(\$|\,)/g,'')), n=parseFloat(c.replace(/(\$|\,)/g,''));
if(!isNaN(i)&&!isNaN(n)){g=i,h=n}
pos = f.indexOf("/"); pos2 = f.lastIndexOf("/");
dX=f.substring(0,pos); mX=f.substring(pos+1,pos2); aX=f.substring(pos2+1,(pos2)+5);
fX=mX+"/"+dX+"/"+aX;
dY=c.substring(0,pos); mY=c.substring(pos+1,pos2); aY=c.substring(pos2+1,(pos2)+5);
fY=mY+"/"+dY+"/"+aY;
i=Date.parse(fX); n=Date.parse(fY);
if(!isNaN(i)&&!isNaN(n)){g=i; h=n}
return g>h?1:(g<h?-1:0)

nacho cano on July 26, 2009 at 7:12 pm

The code doesn't work with more than 5000 lines, any hint of how to handle such an amount of information?

LSJack on July 31, 2009 at 5:39 am

thanks for sharing,i love it so much,I would like to have a question,how to obtain the value of rise sequence and show it?

xiaomin on August 07, 2009 at 2:57 am

This is a great javascript library. Would be great for customer bases with dedicated hosting, virtual private servers, and even reseller hosting to showing top bandwidth usage, GB, MB, memory usage, disk storage, ftp usage, email usage, mysql database usage, and so on. I am thinking of developing a control panel software to maybe include this style of tables.

Great find!

Cameron Gunnufson on August 08, 2009 at 4:24 pm

This is great. Within 5 minutes i had turned a monster 5000 row table into a easy to navigate datasheet… can't wait for the search facility!! Good work :)

Ed on August 11, 2009 at 6:30 am

I'm having issues sorting a column of sku's with variable lengths and numbers/letters in them.. For some reason it's sorting by length, not by actual number/alpha order.. any thoughts? PLEASE HELP!!

DWG on August 11, 2009 at 4:01 pm

If anyone wants to know how to default the sort to DESC on load, do this.

Line 30 should read
else{t.p=y; t.a.sort(cp); t.d=0; x.className=this.asc}

change it to this
else{t.p=y; t.a.sort(cp).reverse(); t.d=0; x.className=this.desc}

if that isn't ur line 30, then just find that line and replace it. Should have the option on init to specify.

Derek on August 11, 2009 at 9:42 pm

Still hoping someone could help me with answer.. here's an example of the sku's that are not sorting properly – it seems to default to the next column over with the descriptions.. all other sorting seems to be working properly.

0723309571
439710-1628
7511SFA2419
20356412IM
8707SV40XT

I also have an example posted here: http://www.thetps.com/tablesort.html

ANY HELP WOULD BE GREATLY APPRECIATED!!! THANKS!

DWG on August 12, 2009 at 11:13 am

Hola, a todos, hice esta prueba con el código para ordenar fechas en formato aaaa-mm-dd, lo unico que agrege es en esta linea,
de:
var i=parseFloat(f.replace(/(\$|\,)/g,'')), n=parseFloat(c.replace(/(\$|\,)/g,''));

por
var i=parseFloat(f.replace(/(\$|\,|\-)/g,'')), n=parseFloat(c.replace(/(\$|\,|\-)/g,''));

y funcionó, espero ha alguien le sirva :) , saludos.

Hello everyone, I have other form for the dates, the solution to order dates in format :yyyy-mm-dd

of:
var i=parseFloat(f.replace(/(\$|\,)/g,'')), n=parseFloat(c.replace(/(\$|\,)/g,''));

to:
var i=parseFloat(f.replace(/(\$|\,|\-)/g,'')), n=parseFloat(c.replace(/(\$|\,|\-)/g,''));

realy works! ;) ,
Regards

adrian on August 13, 2009 at 9:04 am

Is it possible to know which is the number of column sorted out ?
How can I do that ?
For example :
sorter.init("table",2);
document.write (sorter.what ?) => return 2

Thank's for your help

lemoussel on August 17, 2009 at 2:31 am

How to get the current column and order direction:

Write between this to lines (30 and 31) …
else{t.p=y; t.a.sort(cp); t.d=0; x.className=this.asc}
… here …
var n=document.createElement('tbody');
… the returning code like this.

else{t.p=y; t.a.sort(cp); t.d=0; x.className=this.asc}
if(this.currentcolumn){T$(this.currentcolumn).innerHTML=y}
if(this.currentorderdir){T$(this.currentorderdir).innerHTML=x.className}
var n=document.createElement('tbody');

Ad to config init:
sorter.currentcolumn = "current_column";
sorter.currentorderdir = "current_orderdir";

And to your html file:
<div id="current_column"></div>
<div id="current_orderdir"></div>

Thats it!

chris on August 18, 2009 at 10:41 am

Not sure if this script handles <tfoot> tags correctly

js on August 18, 2009 at 4:23 pm

Great script!

I just wanted one row of data to display at a time so I modified the script.js to default to that and deleted the Entries Per Page from the HTML.

Question – I need to change the way the data is displayed. Since I'm only displaying one record at a time, I'd like to shift the table so that the column headings are on the left side going down with the data displayed next to it rather than across the top with the data underneath. How do I do this? Can I do this?

Thanks again.

BT on August 23, 2009 at 1:44 pm

Hello!! this is a usefull javascript code :D

I have a question! How can i fill the table dynamically using php??
for example in a search and fill the table again in base the result!

Regards! :D

PD: sorry by my English is no so good :S

PoMiLLo on August 29, 2009 at 2:02 pm

Hello,
I have tried your code with asp.net. I have used an asp.net listview bind to and objectdatasource. Everything works just great.

Now i have added an select linkbutton with the select command so when i select a row the containing details will be filled out in a asp.net detailsview. Also this detailsview is bount to an objectdatasource.

When i run the page i can select a row and the details get filled in and the paging will remain it's pageindex and pagesize.

Now i have wrapped everything up in an updatepanel. When running the pages i see my grid paged and wile paging my pagesize remains and paging occures correctly. When i click my select button the detailsview get's filled but the page size will be losed. So when i set the pager to 10 records a page and i have 100 total records, the paging will be set to 100. The page dropdownlist has 10 records selected.

I tried to implement the JQuery.NoConflict() theory but this doesn't help.
Will there be a solution for this issue?

Hope so

Great work

Thanks Talsja

talsja on September 01, 2009 at 10:54 am

First of all, this script is amazing. Excellent work! I am having a similar problem to the other posters; my site is using thickbox with links within the table, and there are two sorted tables on the page.

Everything works great at first, the thickbox links work properly, the tables both sort, etc. But once you have sorted one of the tables, the thickbox links within no longer work correctly. Instead of popping up the linked html within the page, they send you to a new one, as it seems the class of the <a> element was removed when the table was sorted.

Any ideas?

Elerium on September 01, 2009 at 8:00 pm

Hi!
Excellent script!
It's possible to sort 2 o 3 column simultaneously?
ex:
name and surname. If to sort name is not possible to sort surname.

Thanks Ivan

Ivan on September 02, 2009 at 5:17 pm

hello!
is possible multiple column sorting like tablesorter?

Ivan on September 02, 2009 at 5:26 pm

Anyone have success wrapping Form tags around this to make each line editable?

DoCBReeD on September 10, 2009 at 8:31 am

When I got the Console error "sorter not defined" I put the sorter declaration above the table. Now I receive in Firebug:
p is null:
T$$("tbody", Object name=p)script.js (line 4)
ge("table-list")script.js (line 53)
anonymous("table-list", 2)script.js (line 9)
list.php?23()

What am i doing wrong? Thanks!

Korsakov on September 14, 2009 at 11:37 am

how do I apply my own styles to cells and rows

fharris on September 18, 2009 at 1:51 pm

Several suggestions:
1. Show the page control buttons dynamically. That is, on the first/last page, hide “first/last page” and “previous/next page” button; when there is only one page, hide all buttons.
2. Add a “go to page {page #}” input box for quick navigation.
3. In the “entries per page” drop-down list, show the actual number instead of a fixed number on the first load of the webpage.
4. Think about this situation. I have a table whose first column is just the row number, and I want it to be fixed when I apply sorting on other columns. It would be better if there is a class for this kind of column.

Eason on September 27, 2009 at 2:49 pm

http://vb2005xu.javaeye.com/blog/481236
Tiny.Table Chinese Char sorter support!

vb2005xu on October 01, 2009 at 8:36 am

hi, it looks very attractive, but can any one tell me about its feedback?

Web design company london on October 02, 2009 at 1:03 am

Very nice script. I found an issue with putting a select list inside a cell of the table. The selected option no longer renders correctly. This works in FireFox, etc. but not IE. Any suggestions would be a great help

wally on October 05, 2009 at 6:52 am

Ach!

Just discovered a really bad feature / bug.

It kills existing cell classes. Really not good :(

Dave Stewart on October 17, 2009 at 10:25 am

Sorry – I appear to be rather good at complaining about such a useful class.

I'm using multiple tables on one page, and from what I can tell I have to instantiate as many table sorter instances as I have tables. As my tables are all being generated by PHP, this makes setting up sorters a rather messy process. What would be really nice would be a single class that manages the sorting of all tables. The best result for me would be for any instantiated sorter class to fire on load, grabbing all the tables of a certain class, perhaps, then initializing them to some internal pointers.

Also, I don't really understand why I have to pass the "sorter" reference back into itself on creation. Is this to create the anonymous function? Surely there must be a cleaner way than this… ?

Cheers,
Dave

Dave Stewart on October 20, 2009 at 7:42 pm

I am creating a results table dynamically with AJAX. On page init the table headers show as sortable, but after a form selection, the AJAX queries the database and re-populates the <tbody> element. This action destroys the sortability until a page refresh is handled.

How can I call a "re-sort" after my AJAX has posted the data back to the table?

Jared Allen on October 22, 2009 at 4:58 pm

This script works great, but I do have one problem with it. I need to have a few rows in my table before the <thead>. I can't put another <thead> because then it will try to use those rows. If it isn't in a <thead>, then those rows will show below and sometimes above the <thead> and the sorting won't work. Any solutions or workarounds for this?
Thanks a lot.

kyle johnson on November 10, 2009 at 10:54 am

Hi all,

This is very amazing script. i already use this in my project and it works very cool. but now i'm facing with some problem which is i dont want number shown on the first of the column to be sorted decreasingly.. i wanna the first column to be static in ascending order while other column is sorted.
Kindly pelase help me.

Thank you very much for your assistance in this matter.

hadiaruz on November 11, 2009 at 9:08 pm

"echo date("M jS",strtotime($result['date']));"

breaks date sorting, if I leave the date in raw mySQL format (i.e. 2009-11-15) it works fine. Any suggestions?

ConixIT on November 13, 2009 at 1:04 pm

First of all, thank you for a great script! Fabulous work. Second: When will the search function arrive? Thanks.

Panthera on November 15, 2009 at 4:59 am

Nice script!

I'm trying to hide some of my table rows, until someone selects a button to display them.
When I do:

<tr style="display:none> … </tr>

The row is still displayed. Any idea on how to keep it hidden through out the sorting
process until my displayRow() button is pushed?

Whitney on November 16, 2009 at 4:16 pm

Excellent script. It would be even more useful when the filtering functionality is added. thanks!

jason on November 19, 2009 at 11:42 am

How do I set the navigation buttons to appear and dissapear based on number of pages? For example in there is only 1 page to view I dont want the navigation buttons to show, or if the user is on page 1 of 3 I dont want the back buttons to be viewable.

Thanks…great script!

MB on November 20, 2009 at 11:35 am

This is an amazing script!!

There is one issue though, after sort, the internal dom references are lost. I have Microsoft presence embedded in one of the columns, after a sort the references to the onhover effect to the presence icon is lost.

Kris A on November 23, 2009 at 10:56 am

really amazing script! works perfectly for me!
One question is : does the Javacript work in Microsoft masterpage?

Thank you very much!

Gary Jia on December 11, 2009 at 12:54 pm

This is truly a great script – it performs so well. Is there any way that you could pass on readable source? It's hard to understand the current one posted.

Thanks!

Biju Philip on December 11, 2009 at 6:02 pm

Wow i love you dude!

Wulst on December 15, 2009 at 4:17 am

Excellent work! But for your next release, please JSLINT it a couple of time to improve the code.

http://www.jslint.com/

Sh0gun on December 18, 2009 at 11:58 am

Good script.. I having a problem with add a new column with checkbox when click any column sort desc that checkbox is not working….

http://www.grabhost.com/tinytable/indextick.html

I’ve added jquery alert tick box – true/false. alert message is not working after click sort column.

Do anyone can resolve this bug? If so, drop me a mail smiler18@hotmail.com

Thank you
Oliver

Oliver on January 12, 2010 at 8:41 am

Hi all,
I started to use another plugin which I will not name names, but it was too complicated and it takes time every time, while yours is super, bravo.
I have a small question, is it possible to record a selection in Excel!?
thanks

aziz on January 18, 2010 at 5:10 am

Hi nacho cano
your script for dd/mm/yyyy is great! thanks :)

Jia on January 26, 2010 at 8:35 am

I´m working with jQuery/TableSorter at the present, but I really like this TinyTable script. jQuery/TableSorter is fine when I also benefit from other possibilities jQuery offer. But when making a table sortable is really the only task to be fullfilled, TinyTable seems like the better solution to me because of its small size. I will try it out soon.

Thomas on February 03, 2010 at 7:11 am

Are this work with PHP+MySQL?

inwebdeveloper on February 08, 2010 at 9:21 pm

These days I managed to implement TinyTable into a table in a Joomla content item. It is really a great tiny script.
It should work with PHP/MySQL, to answer the post before this one, as long as the frontend output is a html table.

Thomas on February 09, 2010 at 8:27 am

Can someone tell me how to sort dates in dd-Mmm-yyyy format?

Ramya on February 16, 2010 at 1:44 am

It appears this script is missing one vital capability of sorters – the ability to customize keys or write a parser. For example, suppose that, in a column to be sorted numerically, the script allows one to specify that ">25" is sorted as if it was "26".

Gerry on February 18, 2010 at 9:03 pm

I insert the script in a complex PHP /MySql Website without any issue.
I only undertake some changes on the css file due to the environment: for example I change thead/th/h3 in thead/th/span because of h3 is used by the website.
Many thanks for this script

Xavier on February 21, 2010 at 12:28 pm

Thanks for the excellent script. Could you advise how I could sort the table, if I have for example values '20 MB', '20 GB' and '20 TB' on one field? Would it be possible to create a 'counterfield' and give '20 TB' value '3', '20 GB' value '2' and '20 MB' value '1' and sort the table showing original values but sorting from "counterfield". Turning all values into same unit MB/GB/TB isnt possible.. Need other way. Can they be given sorting value somehow?

lmn on March 07, 2010 at 8:06 am

Everything works fine, except the “entries per page” selector. It should reset itself on page reload. For eg: if I choose to display 5 records, and next time I refresh the page, it’d display all the records, but the selector continues to display 5.

Hariram on March 17, 2010 at 2:26 pm

Trackbacks

Leave a Reply

General comments only please. Visit forum.leigeber.com for technical discussion.