1.0.1 • Published 3 years ago

jquery-fake-table-sort v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

Efficient table sorter

This jQuery plugin allows to sort data made with any markup, table or not.

Demo

jQuery fake table sort demo

Installation

From npm

npm install melicerte/jquery-fake-table-sort

Use directly in HTML:

<script
  src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
  integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
  crossorigin="anonymous"></script>

Include jQuery Fake Table Sort:

<script src="js/jquery.fakeTableSort.min.js"></script>

Prerequisites

jQuery >= 1.7.0

Usage

jQuery('.table-fake').fakeTableSortable();

With options

jQuery('.table-fake').fakeTableSortable({
    headerItems: 'div.table-fake-row-first > div',
    lineItems: 'div.table-fake-row',
    cellItems: 'div.table-fake-col',
    linesContainers: 'div.table-fake-row-container',
    firstSort: 'asc',
    sortMethods: ['lexicographical', 'lexicographical', 'lexicographical', 'number'],
    textConverter: [null, null, convertDateInterval, null]
});

headerItems : CSS selector to find headers cells in the fake table. Defaults to div.table-fake-row-first > div

lineItems : CSS selector to find content lines in the fake table. Defaults to div.table-fake-row

cellItems : CSS selector to find content cell in content lines Defaults to div.table-fake-col

linesContainer : CSS selector to find The HTML tag containing the rows. Defaults to null, rows are added after headerItems

firstSort : 'asc' or 'desc' : set first wanted order sort. Defaults to 'asc'.

sortMethods : Used to choose the sorting method. Can be either a string or an array. If it is string, the same sort method is used for every column. If it is an array, each value will be used for one column. You can use 'lexicographical' or 'number' sort. Defaults to "lexicographical"

textConverter : Used to convert cell content before comparing for sort. Can be either a function callback or an array of callback functions. If it is string, the text converter callback is used for every column. If it is an array, each callback will be used for its associated column. The callback function must take one argument value, the value to convert, and return the converted value. Defaults to null

Style

You can add style on links added on header items.

They have class fake-table-sorter, plus asc if next action is to sort asc, desc id next action is desc sort

Implementation details

This plugin uses the quicksort algorithm (Lomuto partition scheme).

Authors

  • Etienne Châtaignier - First release