mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-03 14:32:21 +02:00
4481fbe361
branch: master
SHA: c7d6de72f7
range SHA: 81f31a3106fb...c7d6de72f785
build id: 375208741
build number: 1103
686 lines
38 KiB
HTML
686 lines
38 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<base data-ice="baseUrl" href="../../../../">
|
|
<title data-ice="title">src/extensions/sort/adapterSortabletable.js | tablefilter</title>
|
|
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
<script src="script/prettify/prettify.js"></script>
|
|
<script src="script/manual.js"></script>
|
|
<meta name="description" content="A Javascript library making HTML tables filterable and a bit more"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="tablefilter"><meta property="twitter:description" content="A Javascript library making HTML tables filterable and a bit more"></head>
|
|
<body class="layout-container" data-ice="rootContainer">
|
|
|
|
<header>
|
|
<a href="./">Home</a>
|
|
|
|
<a href="identifiers.html">Reference</a>
|
|
<a href="source.html">Source</a>
|
|
|
|
<div class="search-box">
|
|
<span>
|
|
<img src="./image/search.png">
|
|
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
</span>
|
|
<ul class="search-result"></ul>
|
|
</div>
|
|
<a style="position:relative; top:3px;" href="https://github.com/koalyptus/TableFilter.git"><img width="20px" src="./image/github.png"></a></header>
|
|
|
|
<nav class="navigation" data-ice="nav"><div>
|
|
<ul>
|
|
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/emitter.js~Emitter.html">Emitter</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/feature.js~Feature.html">Feature</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/tablefilter.js~TableFilter.html">TableFilter</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-has">has</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-addClass">addClass</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createCheckItem">createCheckItem</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createElm">createElm</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createOpt">createOpt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createText">createText</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-elm">elm</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getFirstTextNode">getFirstTextNode</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getText">getText</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-hasClass">hasClass</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-removeClass">removeClass</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-removeElm">removeElm</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-tag">tag</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-addEvt">addEvt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-cancelEvt">cancelEvt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isKeyPressed">isKeyPressed</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-keyCode">keyCode</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-removeEvt">removeEvt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-stopEvt">stopEvt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-targetEvt">targetEvt</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-parse">parse</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-defaultsArr">defaultsArr</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-defaultsBool">defaultsBool</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-defaultsFn">defaultsFn</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-defaultsNb">defaultsNb</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-defaultsStr">defaultsStr</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-dateSortAsc">dateSortAsc</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-dateSortDesc">dateSortDesc</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ignoreCase">ignoreCase</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-numSortAsc">numSortAsc</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-numSortDesc">numSortDesc</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-sortDateStr">sortDateStr</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-sortNumberStr">sortNumberStr</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-contains">contains</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isEmpty">isEmpty</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-matchCase">matchCase</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-rgxEsc">rgxEsc</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-trim">trim</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-EMPTY_FN">EMPTY_FN</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isArray">isArray</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isBoolean">isBoolean</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isEmpty">isEmpty</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isFn">isFn</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isNull">isNull</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isNumber">isNumber</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isObj">isObj</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isString">isString</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-isUndef">isUndef</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-AUTO_FILTER_DELAY">AUTO_FILTER_DELAY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-CELL_TAG">CELL_TAG</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-CHECKLIST">CHECKLIST</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-DATE">DATE</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-DOWN_ARROW_KEY">DOWN_ARROW_KEY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ENTER_KEY">ENTER_KEY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-ESC_KEY">ESC_KEY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-FEATURES">FEATURES</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-FORMATTED_NUMBER">FORMATTED_NUMBER</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-HEADER_TAG">HEADER_TAG</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-INPUT">INPUT</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-IP_ADDRESS">IP_ADDRESS</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MULTIPLE">MULTIPLE</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NONE">NONE</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NUMBER">NUMBER</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SELECT">SELECT</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-STRING">STRING</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-TAB_KEY">TAB_KEY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-UP_ARROW_KEY">UP_ARROW_KEY</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-root">root</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#extensions-advancedgrid">extensions/advancedGrid</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/extensions/advancedGrid/adapterEzEditTable.js~AdapterEzEditTable.html">AdapterEzEditTable</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#extensions-colops">extensions/colOps</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/extensions/colOps/colOps.js~ColOps.html">ColOps</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#extensions-colsvisibility">extensions/colsVisibility</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/extensions/colsVisibility/colsVisibility.js~ColsVisibility.html">ColsVisibility</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#extensions-filtersvisibility">extensions/filtersVisibility</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/extensions/filtersVisibility/filtersVisibility.js~FiltersVisibility.html">FiltersVisibility</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#extensions-sort">extensions/sort</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/extensions/sort/adapterSortabletable.js~AdapterSortableTable.html">AdapterSortableTable</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#modules">modules</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/alternateRows.js~AlternateRows.html">AlternateRows</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/baseDropdown.js~BaseDropdown.html">BaseDropdown</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/checkList.js~CheckList.html">CheckList</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/clearButton.js~ClearButton.html">ClearButton</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/dateType.js~DateType.html">DateType</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/dropdown.js~Dropdown.html">Dropdown</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/gridLayout.js~GridLayout.html">GridLayout</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/hash.js~Hash.html">Hash</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/help.js~Help.html">Help</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/highlightKeywords.js~HighlightKeyword.html">HighlightKeyword</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/loader.js~Loader.html">Loader</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/markActiveColumns.js~MarkActiveColumns.html">MarkActiveColumns</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/noResults.js~NoResults.html">NoResults</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/paging.js~Paging.html">Paging</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/popupFilter.js~PopupFilter.html">PopupFilter</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/rowsCounter.js~RowsCounter.html">RowsCounter</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/state.js~State.html">State</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/statusBar.js~StatusBar.html">StatusBar</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/storage.js~Storage.html">Storage</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/modules/toolbar.js~Toolbar.html">Toolbar</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-hasHashChange">hasHashChange</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-hasStorage">hasStorage</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-CENTER">CENTER</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-LEFT">LEFT</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-RIGHT">RIGHT</a></span></span></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="content" data-ice="content"><h1 data-ice="title">src/extensions/sort/adapterSortabletable.js</h1>
|
|
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import {Feature} from '../../feature';
|
|
import {isUndef, isObj, EMPTY_FN} from '../../types';
|
|
import {createElm, elm, getText, tag} from '../../dom';
|
|
import {addEvt} from '../../event';
|
|
import {parse as parseNb} from '../../number';
|
|
import {
|
|
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
|
|
IP_ADDRESS
|
|
} from '../../const';
|
|
import {defaultsStr, defaultsFn, defaultsArr} from '../../settings';
|
|
|
|
/**
|
|
* SortableTable Adapter module
|
|
*/
|
|
export default class AdapterSortableTable extends Feature {
|
|
|
|
/**
|
|
* Creates an instance of AdapterSortableTable
|
|
* @param {TableFilter} tf TableFilter instance
|
|
* @param {Object} opts Configuration object
|
|
*/
|
|
constructor(tf, opts) {
|
|
super(tf, opts.name);
|
|
|
|
/**
|
|
* Module name
|
|
* @type {String}
|
|
*/
|
|
this.name = opts.name;
|
|
|
|
/**
|
|
* Module description
|
|
* @type {String}
|
|
*/
|
|
this.desc = defaultsStr(opts.description, 'Sortable table');
|
|
|
|
/**
|
|
* Indicate whether table previously sorted
|
|
* @type {Boolean}
|
|
* @private
|
|
*/
|
|
this.sorted = false;
|
|
|
|
/**
|
|
* List of sort type per column basis
|
|
* @type {Array}
|
|
*/
|
|
this.sortTypes = defaultsArr(opts.types, tf.colTypes);
|
|
|
|
/**
|
|
* Column to be sorted at initialization, ie:
|
|
* sort_col_at_start: [1, true]
|
|
* @type {Array}
|
|
*/
|
|
this.sortColAtStart = defaultsArr(opts.sort_col_at_start, null);
|
|
|
|
/**
|
|
* Enable asynchronous sort, if triggers are external
|
|
* @type {Boolean}
|
|
*/
|
|
this.asyncSort = Boolean(opts.async_sort);
|
|
|
|
/**
|
|
* List of element IDs triggering sort on a per column basis
|
|
* @type {Array}
|
|
*/
|
|
this.triggerIds = defaultsArr(opts.trigger_ids, []);
|
|
|
|
// edit .sort-arrow.descending / .sort-arrow.ascending in
|
|
// tablefilter.css to reflect any path change
|
|
/**
|
|
* Path to images
|
|
* @type {String}
|
|
*/
|
|
this.imgPath = defaultsStr(opts.images_path, tf.themesPath);
|
|
|
|
/**
|
|
* Blank image file name
|
|
* @type {String}
|
|
*/
|
|
this.imgBlank = defaultsStr(opts.image_blank, 'blank.png');
|
|
|
|
/**
|
|
* Css class for sort indicator image
|
|
* @type {String}
|
|
*/
|
|
this.imgClassName = defaultsStr(opts.image_class_name, 'sort-arrow');
|
|
|
|
/**
|
|
* Css class for ascending sort indicator image
|
|
* @type {String}
|
|
*/
|
|
this.imgAscClassName = defaultsStr(opts.image_asc_class_name,
|
|
'ascending');
|
|
|
|
/**
|
|
* Css class for descending sort indicator image
|
|
* @type {String}
|
|
*/
|
|
this.imgDescClassName = defaultsStr(opts.image_desc_class_name,
|
|
'descending');
|
|
|
|
/**
|
|
* Cell attribute key storing custom value used for sorting
|
|
* @type {String}
|
|
*/
|
|
this.customKey = defaultsStr(opts.custom_key, 'data-tf-sortKey');
|
|
|
|
/**
|
|
* Callback fired when sort extension is instanciated
|
|
* @type {Function}
|
|
*/
|
|
this.onSortLoaded = defaultsFn(opts.on_sort_loaded, EMPTY_FN);
|
|
|
|
/**
|
|
* Callback fired before a table column is sorted
|
|
* @type {Function}
|
|
*/
|
|
this.onBeforeSort = defaultsFn(opts.on_before_sort, EMPTY_FN);
|
|
|
|
/**
|
|
* Callback fired after a table column is sorted
|
|
* @type {Function}
|
|
*/
|
|
this.onAfterSort = defaultsFn(opts.on_after_sort, EMPTY_FN);
|
|
|
|
/**
|
|
* SortableTable instance
|
|
* @private
|
|
*/
|
|
this.stt = null;
|
|
|
|
this.enable();
|
|
}
|
|
|
|
/**
|
|
* Initializes AdapterSortableTable instance
|
|
*/
|
|
init() {
|
|
if (this.initialized) {
|
|
return;
|
|
}
|
|
let tf = this.tf;
|
|
let adpt = this;
|
|
|
|
// SortableTable class sanity check (sortabletable.js)
|
|
if (isUndef(SortableTable)) {
|
|
throw new Error('SortableTable class not found.');
|
|
}
|
|
|
|
// Add any date format if needed
|
|
this.emitter.emit('add-date-type-formats', this.tf, this.sortTypes);
|
|
|
|
this.overrideSortableTable();
|
|
this.setSortTypes();
|
|
|
|
this.onSortLoaded(tf, this);
|
|
|
|
/*** SortableTable callbacks ***/
|
|
this.stt.onbeforesort = function () {
|
|
adpt.onBeforeSort(tf, adpt.stt.sortColumn);
|
|
|
|
/*** sort behaviour for paging ***/
|
|
if (tf.paging) {
|
|
tf.feature('paging').disable();
|
|
}
|
|
};
|
|
|
|
this.stt.onsort = function () {
|
|
adpt.sorted = true;
|
|
|
|
//sort behaviour for paging
|
|
if (tf.paging) {
|
|
let paginator = tf.feature('paging');
|
|
// recalculate valid rows index as sorting may have change it
|
|
tf.getValidRows(true);
|
|
paginator.enable();
|
|
paginator.setPage(paginator.getPage());
|
|
}
|
|
|
|
adpt.onAfterSort(tf, adpt.stt.sortColumn, adpt.stt.descending);
|
|
adpt.emitter.emit('column-sorted', tf, adpt.stt.sortColumn,
|
|
adpt.stt.descending);
|
|
};
|
|
|
|
// Column sort at start
|
|
let sortColAtStart = adpt.sortColAtStart;
|
|
if (sortColAtStart) {
|
|
this.stt.sort(sortColAtStart[0], sortColAtStart[1]);
|
|
}
|
|
|
|
this.emitter.on(['sort'],
|
|
(tf, colIdx, desc) => this.sortByColumnIndex(colIdx, desc));
|
|
|
|
/** @inherited */
|
|
this.initialized = true;
|
|
|
|
this.emitter.emit('sort-initialized', tf, this);
|
|
}
|
|
|
|
/**
|
|
* Sort specified column
|
|
* @param {Number} colIdx Column index
|
|
* @param {Boolean} desc Optional: descending manner
|
|
*/
|
|
sortByColumnIndex(colIdx, desc) {
|
|
this.stt.sort(colIdx, desc);
|
|
}
|
|
|
|
/**
|
|
* Set SortableTable overrides for TableFilter integration
|
|
*/
|
|
overrideSortableTable() {
|
|
let adpt = this,
|
|
tf = this.tf;
|
|
|
|
/**
|
|
* Overrides headerOnclick method in order to handle th event
|
|
* @param {Object} e [description]
|
|
*/
|
|
SortableTable.prototype.headerOnclick = function (evt) {
|
|
if (!adpt.initialized) {
|
|
return;
|
|
}
|
|
|
|
// find Header element
|
|
let el = evt.target || evt.srcElement;
|
|
|
|
while (el.tagName !== CELL_TAG && el.tagName !== HEADER_TAG) {
|
|
el = el.parentNode;
|
|
}
|
|
|
|
this.sort(
|
|
SortableTable.msie ?
|
|
SortableTable.getCellIndex(el) : el.cellIndex
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Overrides getCellIndex IE returns wrong cellIndex when columns are
|
|
* hidden
|
|
* @param {Object} oTd TD element
|
|
* @return {Number} Cell index
|
|
*/
|
|
SortableTable.getCellIndex = function (oTd) {
|
|
let cells = oTd.parentNode.cells,
|
|
l = cells.length, i;
|
|
for (i = 0; cells[i] !== oTd && i < l; i++) { }
|
|
return i;
|
|
};
|
|
|
|
/**
|
|
* Overrides initHeader in order to handle filters row position
|
|
* @param {Array} oSortTypes
|
|
*/
|
|
SortableTable.prototype.initHeader = function (oSortTypes) {
|
|
let stt = this;
|
|
if (!stt.tHead) {
|
|
if (tf.gridLayout) {
|
|
stt.tHead = tf.feature('gridLayout').headTbl.tHead;
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
stt.headersRow = tf.headersRow;
|
|
let cells = stt.tHead.rows[stt.headersRow].cells;
|
|
stt.sortTypes = oSortTypes || [];
|
|
let l = cells.length;
|
|
let img, c;
|
|
|
|
for (let i = 0; i < l; i++) {
|
|
c = cells[i];
|
|
if (stt.sortTypes[i] !== null && stt.sortTypes[i] !== 'None') {
|
|
c.style.cursor = 'pointer';
|
|
img = createElm('img',
|
|
['src', adpt.imgPath + adpt.imgBlank]);
|
|
c.appendChild(img);
|
|
if (stt.sortTypes[i] !== null) {
|
|
c.setAttribute('_sortType', stt.sortTypes[i]);
|
|
}
|
|
addEvt(c, 'click', stt._headerOnclick);
|
|
} else {
|
|
c.setAttribute('_sortType', oSortTypes[i]);
|
|
c._sortType = 'None';
|
|
}
|
|
}
|
|
stt.updateHeaderArrows();
|
|
};
|
|
|
|
/**
|
|
* Overrides updateHeaderArrows in order to handle arrows indicators
|
|
*/
|
|
SortableTable.prototype.updateHeaderArrows = function () {
|
|
let stt = this;
|
|
let cells, l, img;
|
|
|
|
// external headers
|
|
if (adpt.asyncSort && adpt.triggerIds.length > 0) {
|
|
let triggers = adpt.triggerIds;
|
|
cells = [];
|
|
l = triggers.length;
|
|
for (let j = 0; j < l; j++) {
|
|
cells.push(elm(triggers[j]));
|
|
}
|
|
} else {
|
|
if (!this.tHead) {
|
|
return;
|
|
}
|
|
cells = stt.tHead.rows[stt.headersRow].cells;
|
|
l = cells.length;
|
|
}
|
|
for (let i = 0; i < l; i++) {
|
|
let cell = cells[i];
|
|
if (!cell) {
|
|
continue;
|
|
}
|
|
let cellAttr = cell.getAttribute('_sortType');
|
|
if (cellAttr !== null && cellAttr !== 'None') {
|
|
img = cell.lastChild || cell;
|
|
if (img.nodeName.toLowerCase() !== 'img') {
|
|
img = createElm('img',
|
|
['src', adpt.imgPath + adpt.imgBlank]);
|
|
cell.appendChild(img);
|
|
}
|
|
if (i === stt.sortColumn) {
|
|
img.className = adpt.imgClassName + ' ' +
|
|
(this.descending ?
|
|
adpt.imgDescClassName :
|
|
adpt.imgAscClassName);
|
|
} else {
|
|
img.className = adpt.imgClassName;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Overrides getRowValue for custom key value feature
|
|
* @param {Object} oRow Row element
|
|
* @param {String} sType
|
|
* @param {Number} nColumn
|
|
* @return {String}
|
|
*/
|
|
SortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {
|
|
let stt = this;
|
|
// if we have defined a custom getRowValue use that
|
|
let sortTypeInfo = stt._sortTypeInfo[sType];
|
|
if (sortTypeInfo && sortTypeInfo.getRowValue) {
|
|
return sortTypeInfo.getRowValue(oRow, nColumn);
|
|
}
|
|
let c = oRow.cells[nColumn];
|
|
let s = SortableTable.getInnerText(c);
|
|
return stt.getValueFromString(s, sType);
|
|
};
|
|
|
|
/**
|
|
* Overrides getInnerText in order to avoid Firefox unexpected sorting
|
|
* behaviour with untrimmed text elements
|
|
* @param {Object} oNode DOM element
|
|
* @return {String} DOM element inner text
|
|
*/
|
|
SortableTable.getInnerText = function (oNode) {
|
|
if (!oNode) {
|
|
return;
|
|
}
|
|
if (oNode.getAttribute(adpt.customKey)) {
|
|
return oNode.getAttribute(adpt.customKey);
|
|
} else {
|
|
return getText(oNode);
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Adds a sort type
|
|
*/
|
|
addSortType(...args) {
|
|
// Extract the arguments
|
|
let [id, caster, sorter] = args;
|
|
SortableTable.prototype.addSortType(id, caster, sorter);
|
|
}
|
|
|
|
/**
|
|
* Sets the sort types on a column basis
|
|
* @private
|
|
*/
|
|
setSortTypes() {
|
|
let tf = this.tf,
|
|
sortTypes = this.sortTypes,
|
|
_sortTypes = [];
|
|
|
|
tf.eachCol((i) => {
|
|
let colType;
|
|
if (sortTypes[i]) {
|
|
colType = sortTypes[i];
|
|
if (isObj(colType)) {
|
|
if (colType.type === DATE) {
|
|
colType = this._addDateType(i, sortTypes);
|
|
}
|
|
else if (colType.type === FORMATTED_NUMBER) {
|
|
let decimal = colType.decimal || tf.decimalSeparator;
|
|
colType = this._addNumberType(i, decimal);
|
|
}
|
|
} else {
|
|
colType = colType.toLowerCase();
|
|
if (colType === DATE) {
|
|
colType = this._addDateType(i, sortTypes);
|
|
}
|
|
else if (colType === FORMATTED_NUMBER ||
|
|
colType === NUMBER) {
|
|
colType = this._addNumberType(i, tf.decimalSeparator);
|
|
}
|
|
else if (colType === NONE) {
|
|
// TODO: normalise 'none' vs 'None'
|
|
colType = 'None';
|
|
}
|
|
}
|
|
} else {
|
|
colType = STRING;
|
|
}
|
|
_sortTypes.push(colType);
|
|
});
|
|
|
|
//Public TF method to add sort type
|
|
|
|
//Custom sort types
|
|
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
|
this.addSortType(STRING);
|
|
this.addSortType(IP_ADDRESS, ipAddress, sortIP);
|
|
|
|
this.stt = new SortableTable(tf.dom(), _sortTypes);
|
|
|
|
/*** external table headers adapter ***/
|
|
if (this.asyncSort && this.triggerIds.length > 0) {
|
|
let triggers = this.triggerIds;
|
|
for (let j = 0; j < triggers.length; j++) {
|
|
if (triggers[j] === null) {
|
|
continue;
|
|
}
|
|
let trigger = elm(triggers[j]);
|
|
if (trigger) {
|
|
trigger.style.cursor = 'pointer';
|
|
|
|
addEvt(trigger, 'click', (evt) => {
|
|
let elm = evt.target;
|
|
if (!this.tf.sort) {
|
|
return;
|
|
}
|
|
this.stt.asyncSort(triggers.indexOf(elm.id));
|
|
});
|
|
trigger.setAttribute('_sortType', _sortTypes[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
_addDateType(colIndex, types) {
|
|
let tf = this.tf;
|
|
let dateType = tf.feature('dateType');
|
|
let locale = dateType.getOptions(colIndex, types).locale || tf.locale;
|
|
let colType = `${DATE}-${locale}`;
|
|
|
|
this.addSortType(colType, (value) => {
|
|
let parsedDate = dateType.parse(value, locale);
|
|
// Invalid date defaults to Wed Feb 04 -768 11:00:00
|
|
return isNaN(+parsedDate) ? new Date(-86400000000000) : parsedDate;
|
|
});
|
|
return colType;
|
|
}
|
|
|
|
_addNumberType(colIndex, decimal) {
|
|
let colType = `${FORMATTED_NUMBER}${decimal === '.' ? '' : '-custom'}`;
|
|
|
|
this.addSortType(colType, (value) => {
|
|
return parseNb(value, decimal);
|
|
});
|
|
return colType;
|
|
}
|
|
|
|
/**
|
|
* Remove extension
|
|
*/
|
|
destroy() {
|
|
if (!this.initialized) {
|
|
return;
|
|
}
|
|
let tf = this.tf;
|
|
this.emitter.off(['sort'],
|
|
(tf, colIdx, desc) => this.sortByColumnIndex(colIdx, desc));
|
|
this.sorted = false;
|
|
this.stt.destroy();
|
|
|
|
let ids = tf.getFiltersId();
|
|
for (let idx = 0; idx < ids.length; idx++) {
|
|
let header = tf.getHeaderElement(idx);
|
|
let img = tag(header, 'img');
|
|
|
|
if (img.length === 1) {
|
|
header.removeChild(img[0]);
|
|
}
|
|
}
|
|
this.initialized = false;
|
|
}
|
|
|
|
}
|
|
|
|
//Converters
|
|
function ipAddress(value) {
|
|
let vals = value.split('.');
|
|
for (let x in vals) {
|
|
let val = vals[x];
|
|
while (3 > val.length) {
|
|
val = '0' + val;
|
|
}
|
|
vals[x] = val;
|
|
}
|
|
return vals.join('.');
|
|
}
|
|
|
|
function sortIP(a, b) {
|
|
let aa = ipAddress(a.value.toLowerCase());
|
|
let bb = ipAddress(b.value.toLowerCase());
|
|
if (aa === bb) {
|
|
return 0;
|
|
} else if (aa < bb) {
|
|
return -1;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
</code></pre>
|
|
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
</footer>
|
|
|
|
<script src="script/search_index.js"></script>
|
|
<script src="script/search.js"></script>
|
|
<script src="script/pretty-print.js"></script>
|
|
<script src="script/inherited-summary.js"></script>
|
|
<script src="script/test-summary.js"></script>
|
|
<script src="script/inner-link.js"></script>
|
|
<script src="script/patch-for-local.js"></script>
|
|
</body>
|
|
</html>
|