A jQuery plugin for making html tables searchable and sortable with pagination

Overview

jQuery.fancyTable

A jQuery plugin for making html tables searchable and sortable with pagination.

Build Status GitHub

Live demo

See a live demo on CodePen

Installation

Using npm

npm install jquery.fancytable --save

Using CDN

<script src="https://cdn.jsdelivr.net/npm/jquery.fancytable/dist/fancyTable.min.js"></script>

Or manually by including the script after the jQuery library

<script src="/path/to/fancyTable.min.js"></script>

Usage

<script type="text/javascript">
	$(document).ready(function() {
		$(".sampleTable").fancyTable({
			sortColumn:0,
			pagination: true,
			perPage:10,
			globalSearch:true
		});		
	});
</script>

Options

exactMatch - Use exact match. If set to true, search will not match substrings such as "cat" in "catastrophic". If set to "auto", search will be exact if the search term is enclosed in quotation marks.

exactMatch: true

Default: false

globalSearch - Use global search for all columns

globalSearch: false

Default: false

globalSearchExcludeColumns - Defines a number of columns to exclude from the global search.

globalSearchExcludeColumns: [2,5] // Exclude 2nd and 5th column.

Default: undefined

inputPlaceholder - Placeholder to use for <input>

inputPlaceholder: 'Sök...'

Default: 'Search...'

inputStyle - Style attributes to use for <input>

inputStyle: 'color:black;'

Default: ''

matchCase - Use case sensitive search

matchCase: true

Default: false

onInit - Function called after initialization

onInit:function(){
	console.log({ element:this });
}

onUpdate - Function called after each update (sort and search)

onUpdate:function(){
	console.log({ element:this });
}

pagination - Use pagination or not

pagination: true

Default: false

paginationClass - CSS class to use for pagination buttons

pagination: 'btn btn-primary'

Default: 'btn btn-light'

paginationClassActive - CSS class to use for active pagination buttons

pagination: 'someClass'

Default: 'active'

paginationElement - Selector for element to place pagination controls in.

paginationElement: '#someElement'

Default: undefined - Undefined will create a (remove any existing) table footer to place controls in.

pagClosest - Create pagination buttons for tbe n closest pages

pagClosest: 5

Default: 3

perPage - Rows per page when using pagination

perPage: 5

Default: 10

searchable - Should the table be searchable or not

searchable: false

Default: true

sortable - Should the table be sortable or not

sortable: false

Default: true

sortColumn - Column number for initial sorting

sortColumn: 5

Default: undefined

sortFunction - Function for custom sorting

sortFunction: function(a, b, fancyTableObject, rowA, rowB){
	if(a==b && rowA && rowB){
		return(fancyTableObject.rowSortOrder[$(rowA).data("rowid")] > fancyTableObject.rowSortOrder[$(rowB).data("rowid")]);
	}
	if(fancyTableObject.sortAs[fancyTableObject.sortColumn] == 'numeric'){
		return(
			(fancyTableObject.sortOrder>0) ? parseFloat(a)-parseFloat(b) : parseFloat(b)-parseFloat(a)
		);
	} else {
		return((a<b)?-fancyTableObject.sortOrder:(a>b)?fancyTableObject.sortOrder:0);
	}
}

sortOrder - Initial sort order

sortOrder: 'descending' // Valid values are 'desc', 'descending', 'asc', 'ascending', -1 (descending) and 1 (ascending)

Default: 'ascending'

Data attributes

data-sortas="numeric" - Used in the table header element to define that values in the column should be sorted in numerical order (..., 8, 9, 10, 10.1, 12, ...)

<th data-sortas="numeric">

data-sortas="case-insensitive" - Used in the table header element to define that values in the column should be sorted case insensitive (a, B, c, D, ...)

<th data-sortas="case-insensitive">

data-sortvalue="<value>" - Used in the table data element to define an alternate value to be used when sorting

<td>1</td>
<td data-sortvalue="2">Two</td>
<td>3</td>

<td>Ghost</td>
<td data-sortvalue="Fox and the Hound, The">The Fox and the Hound</td>
<td>I Know What You Did Last Summer</td>

Author: Johan Johansson

Comments
  • Consecutive sorts mess up the order

    Consecutive sorts mess up the order

    I have a table with 396 elements, and two of the columns contains a random string witch starts with a number. Every row has a data-sortvalue, which is set to the given number of the start of the random string. The data-sortas is set to numeric, so everything should be fine. But if I sort the first column, then the second, then the first again, then the sort won't be correct.

    question 
    opened by Rodnan 8
  • Accessibility: aria-sort attributes

    Accessibility: aria-sort attributes

    For tables that have sorting enabled, they should:

    1. Use an accessible control to enable sorting (like the <button> element) with an accessible name, aria-labelledby or aria-label to denote what the control does.
      • FancyTable does this via the <a> tag and puts the content of the <th> in the <a> tag as the accessible name. That works ✔️.
    2. Apply aria-sort attributes to table headers (<th>) that change based off of the state of the table.

    For some background on aria-sort, see Sortable Table Columns by Adrian Roselli. The Basics and Sort Arrows sections of that article are especially relevant.

    enhancement 
    opened by adamjohnson 6
  • Sorting with filesizes

    Sorting with filesizes

    Hi, be able integrate data sorting on the file size according to said KB, MB, GB, TB into the table, such as this plugin? https://github.com/DataTables/Plugins/blob/master/sorting/file-size.js or possibly https://mottie.github.io/tablesorter/docs/example-parsers-metric.html Thank you

    enhancement 
    opened by SAGOnly 6
  • pagination buttons class

    pagination buttons class

    Hi, the plugin adds the class defined in paginationClassActive to the active page button. Using bootstrap and this is the pagination part of the fancyTable initialization:

    `paginationClass:"btn btn-outline-primary",

    paginationClassActive:"btn-primary" ` The resulting active button has class "btn btn-outline-primary btn-primary", that results in a blue button with blue text. Is there a way to substitute the entire active button class with the classes defined in paginationClassActive?

    opened by FabrizioReitano 4
  • Feature Request: Support exact match, or provide hooks to enable doing so in custom code

    Feature Request: Support exact match, or provide hooks to enable doing so in custom code

    It would be great to have a way to search for an exact match to the search string. Especially with numbers, when searching for "13" I get all rows with a number that includes "13" anywhere. Familiar syntax for this is simply to put the search string in quotes.

    I wouldn't mind doing some of the work myself, but it seems like the library should allow for that rather than my hacking and potentially interfering with the functioning. Something similar was suggested in issue #10

    Thanks!

    enhancement 
    opened by mjsambol 4
  • Maximum call stack size exceeded RangeError: Maximum call stack size exceeded

    Maximum call stack size exceeded RangeError: Maximum call stack size exceeded

    Hi, I am getting the maximum call stack exceeded error in chrome when the number of records exceed 10k limit. Jquery doesn't do the pagination of html content and throws the below error in console. jQuery.Deferred exception: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded at Function.se [as find] (http://localhost:4200/scripts.js:2:6350) at k.fn.init.find (http://localhost:4200/scripts.js:2:24471) at HTMLTableElement. (http://localhost:4200/scripts.js:126:22) at Function.each (http://localhost:4200/scripts.js:2:2777) at k.fn.init.each (http://localhost:4200/scripts.js:2:1419) at k.fn.init.$.fn.fancyTable (http://localhost:4200/scripts.js:119:8) at HTMLDocument. (http://localhost:4200/main.js:1688:36) at e (http://localhost:4200/scripts.js:2:29453) at t (http://localhost:4200/scripts.js:2:29755) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2785:31) undefined

    While it works find in firefox. Can you please provide any idea what would be causing this issue.

    wontfix 
    opened by vatechie 3
  • Write search parameter to url param

    Write search parameter to url param

    Hi!

    It would be nice to have an option to read/write the search param to the page url with something like "window.history.replaceState" so that search can be maintained when page is refreshed

    enhancement 
    opened by Moustachauve 2
  • Add a responsive option

    Add a responsive option

    Hi Johan, Great solution.

    Have you thought about adding a responsive option? Example: responsive: true

    If responsive: true then:

    1. the attribute "data-th" is set by fancyTable.js, and
    2. the user sets @media ... td:before { content: attr(data-th); display: block; ... } in CSS

    Reference: https://codepen.io/Robot/pen/bdgRQg

    Small and elegant.

    regards

    enhancement 
    opened by thomas-price 2
  • Accessibility: Include sortable table headers in the tab order

    Accessibility: Include sortable table headers in the tab order

    One of the most important tenets of accessibility is making sure all controls can be tabbed to using the Tab key.

    If you visit the demo on CodePen and try tabbing with your tab key to "Col A/B/C", you'll notice you can't reach those controls with just your tab key. This is because the tags don't have href="#" attributes.

    How to fix:

    So, my suggestion would be to either make these elements <button>'s (here's my reasoning) or add href="#" to the anchor tags.

    1. Button:
    <button data-n="0" type="button">
      Col A
      <div class="sortArrow" style="margin: 0.1em; display: inline-block; width: 0px; height: 0px; border-left: 0.4em solid transparent; border-right: 0.4em solid transparent; border-top: 0.4em solid rgb(0, 0, 0);"></div>
    </button>
    
    1. <a> with href="#":
    <a data-n="0" href="#">
      Col A
      <div class="sortArrow" style="margin: 0.1em; display: inline-block; width: 0px; height: 0px; border-left: 0.4em solid transparent; border-right: 0.4em solid transparent; border-top: 0.4em solid rgb(0, 0, 0);"></div>
    </a>
    
    enhancement 
    opened by adamjohnson 2
  • <th data-sortas= not working">

    not working

    When I add this flag I still get numbers sorted as 1, 13, 14, 16, 2, 22, 25, 3, 31 etc. Is this a known bug?

    Is there a way to do an exact match but only on some columns?

    question 
    opened by RZSysadmin 1
  • Set the data-sortvalue value dynamically?

    Set the data-sortvalue value dynamically?

    Is it possible to set the "data-sortvalue" value dynamically? As in, pass in a call to a javascript function, e.g. <td data-sortvalue="textToNumber('Text')">Text</td> where the textToNumber() function converts text to a value used in sorting?

    Not an issue 
    opened by tetsujin1979 1
Owner
null
This is a jquery ui sortable helper plugin for handy tree type structure sotable.

Tree Sortable A drag and drop list item sorting and level changing library. Motivation The jQuery-ui's sortable plugin allows us to sort items vertica

Sajeeb Ahamed 10 Dec 23, 2022
An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor.

Obsidian Excel to Markdown Table An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor. Demo You can paste the copied Excel d

Ganessh Kumar 108 Jan 4, 2023
a jquery searchable select dropdown

Select Search A simple jquery search on select options plugin for your website How To Use Just create an html structure that contains select tag e.g.

Juliver Galleto 1 Sep 25, 2020
caniuse.com but for PHP - a searchable list of new and deprecated features in recent PHP versions

caniphp.com caniphp.com is like caniuse.com but for PHP features. It's a simple search of PHP features that added, deprecated and removed in recent ve

Ross Wintle 95 Dec 25, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Universally Unique Lexicographically Sortable Identifier

Universally Unique Lexicographically Sortable Identifier UUID can be suboptimal for many uses-cases because: It isn't the most character efficient way

ULID 2.1k Jan 2, 2023
🧬 A type builder for pagination with prisma and type-graphql.

?? Prisma TypeGraphql Pagination Prisma TypeGraphql Pagination builds prisma pagination types for type-graphql. import { ... } from 'type-graphql'

Arthur Fiorette 2 Apr 21, 2022
Holy Qur'an Telegram Bot with pagination and audio, in Indonesian language.

quran-telegram-bot Contributions are Welcome! Demo @fio_quran_bot Run Tested on Node.js v14.x.x with NPM v6.x.x, Windows 10 and Ubuntu 18.04.6 LTS. Cr

Rioze 5 Oct 21, 2022
URL Shortener API in NodeJS supporting pagination, sort params and lot more

node-url-shortener Built with ❤️ in NodeJS A simple URL Shortner REST API that uses shortid npm package to generate short endpoints for your long URL.

Dhairya Ostwal 3 Sep 22, 2022
Simple and easy-to-use pagination library for Mongoose (Node.js)

node-paginator Simple and easy-to-use pagination library for Mongoose (Node.js) ?? Why node-paginator? Every web developer should work on pagination a

CareerDay 2 Sep 21, 2022
A simple javascript library for pagination, compatible with Bootstrap.

Easy Pagination JS A simple library for pagination, compatible with Bootstrap. Check my website here. Demo Check this Demo here. Example Import the fi

Wilfredo Paiz 18 Aug 5, 2022
A handler to create embedded pages with buttons for pagination.

➝ Whats that • A handler to create embedded pages with buttons for pagination. ➝ Requirements • ["Handler"] pages.js • [Example command] embed.js ➝ Us

null 8 Oct 30, 2022
Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.

Jspreadsheet CE v4: The JavaScript spreadsheet Jexcel CE has been renamed to Jspreadsheet CE News Important: Please import jspreadsheet.css (jexcel.cs

null 6.2k Dec 19, 2022
An Obsidian Plugin that allows to export tables from a pane in reading mode to CSV files.

Obsidian Plugin "Table to CSV Exporter" This is my very first attempt in writing a plugin for Obsidian. I didn't even know TypeScript before (but Java

Stefan Wolfrum 26 Dec 27, 2022
Making(Creating , Modifying , Deleting) Lists you have to do 😎 Built Only with Html, JavaScript, Css

To-Do_App Live Demo You Can See The Project Live On: Here Description A Simple To-Do App Mainly Written In Javascript The project structure is kinda l

null 6 Nov 2, 2022
Small library for making box selections on HTML elements in JavaScript

Box Selection Small JavaScript library for making box selections on HTML elements. Makes use of CSS transforms so there is no paint flashing. Installa

Kevin Karsopawiro 2 Oct 28, 2021