GithubHelp home page GithubHelp logo

max19931 / tsorter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from terrilldent/tsorter

0.0 1.0 0.0 14 KB

JavaScript Table Sorter using Quick Sort

Home Page: http://www.terrill.ca/sorting

License: MIT License

JavaScript 100.00%

tsorter's Introduction

#tsorter

JavaScript Table Sorter using in-place QuickSort.

Full Details: http://www.terrill.ca/sorting/

Provide the table ID and the initially sorted column (optional):

 var sorter = tsorter.create( tableID, initialSortColumn );

##Specifying Data Types

Different data types require different comparisons. Numbers in particular must be compared as numbers and not strings. To aid the script we can hint at the data type by specifying a data-tsorter attribute on the table header cell for each column.

<thead>
    <tr>
         <th data-tsorter="numeric">Year</th>
         <th data-tsorter="numeric">Population</th>
         <th>Country</th>
    </tr>
</thead>

If the data-tsorter attribute is omitted it will default to string comparison.

##Built in Data Types

type description
numeric Treats the table cell value as an integer or float
link Parses the text content of a link tag inside the table cell
input Parses an input tag's value inside the table cell
default by default the textContent of the table cell is used and compared as text

##Custom Data Accessor

It is possible to define your own data accessors. This is particularly useful when there is custom HTML inside a table cell.

 var sorter = tsorter.create('table-id', 0, {
     'image-number': function(row){  
         return parseFloat( this.getCell(row).childNodes[1].nodeValue, 10 );
     }
});

In the above example the 'image-number' type is now available to be used as a data-tsorter attribute value. It will access the text node that follows an image tag inside a cell. An example is available at http://www.terrill.ca/sorting/table_sort_example.html.

tsorter's People

Contributors

terrilldent avatar

Watchers

James Cloos avatar

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.