All Projects → rdmurphy → Tablesift.js

rdmurphy / Tablesift.js

Sorting HTML tables quickly.

Programming Languages

javascript
184084 projects - #8 most used programming language

TableSift

Let's get this party started.

Siftin'

How to Use

TableSift.init(<id of table> (str) -or- <reference to table> (HTMLTableElement), <options> (object));

Default options

{
    classAsc: 'sift-asc',  // class applied to columns sorted ascending
    classDes: 'sift-des',  // class applied to columns sorted descending
    customSort: {},  // custom functions to parse a column's cells, none by default
    noSort: [],  // don't active a sort feature on provided column indexes, none by default
    removeChars: [',', '$']  // ignore these characters when determining value for sort
}

Different class names for sorted columns

{
    classAsc: 'sorted-a',
    classDes: 'sorted-d'
}

Custom sorter for column index 2, parses number from a cell's text content

{
    customSort: {
        2: function(con, el) {  // 'con' == the cell's text, 'el' == the actual cell element
            return +con.match(/\d+/)[0];  // regex to find number in string, pull it out, and convert to number
        }
    }
}

Don't enable sorting for column index 3

{
    noSort: [3]  // can take comma-delimited entry
}

removeChars

{
    removeChars: [',', '£']  // comma-delimited characters to ignore; for example, pounds instead of dollars
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].