mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-10 02:16:40 +02:00
Initial commit
This commit is contained in:
parent
08b244cbc4
commit
035801dc7e
12
dist/starter.html
vendored
12
dist/starter.html
vendored
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>tablefilter v0.2.65 - Starter</title>
|
||||
<title>tablefilter v0.3.0 - Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>tablefilter v0.2.65</h1>
|
||||
<h1>tablefilter v0.3.0</h1>
|
||||
|
||||
|
||||
|
||||
|
@ -460,10 +460,10 @@
|
|||
status_bar: true,
|
||||
mark_active_columns: true,
|
||||
highlight_keywords: true,
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
'US', 'US', 'US',
|
||||
'US', 'US', 'US'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
custom_options: {
|
||||
cols:[3],
|
||||
|
|
4
dist/tablefilter/style/colsVisibility.css
vendored
4
dist/tablefilter/style/colsVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
span.colVisSpan{text-align:left;}span.colVisSpan a.colVis{display:inline-block;padding:7px 5px 0;font-size:inherit;font-weight:inherit;vertical-align:top}div.colVisCont{position:relative;background:#fff;-webkit-box-shadow:3px 3px 2px #888;-moz-box-shadow:3px 3px 2px #888;box-shadow:3px 3px 2px #888;position:absolute;display:none;border:1px solid #ccc;height:auto;width:250px;background-color:#fff;margin:35px 0 0 -100px;z-index:10000;padding:10px 10px 10px 10px;text-align:left;font-size:12px;}div.colVisCont:after,div.colVisCont:before{bottom:100%;left:50%;border:solid transparent;content:" ";height:0;width:0;position:absolute;pointer-events:none}div.colVisCont:after{border-color:rgba(255,255,255,0);border-bottom-color:#fff;border-width:10px;margin-left:-10px}div.colVisCont:before{border-color:rgba(255,255,255,0);border-bottom-color:#ccc;border-width:12px;margin-left:-12px}div.colVisCont p{margin:6px auto 6px auto}div.colVisCont a.colVis{display:initial;font-weight:inherit}ul.cols_checklist{padding:0;margin:0;list-style:none;}ul.cols_checklist label{display:block}ul.cols_checklist input{vertical-align:middle;margin:2px 5px 2px 1px}li.cols_checklist_item{padding:4px;margin:0;}li.cols_checklist_item:hover{background-color:#335ea8;color:#fff}.cols_checklist_slc_item{background-color:#335ea8;color:#fff}
|
4
dist/tablefilter/style/filtersVisibility.css
vendored
4
dist/tablefilter/style/filtersVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
span.expClpFlt a.btnExpClpFlt{width:35px;height:35px;display:inline-block;}span.expClpFlt a.btnExpClpFlt:hover{background-color:#f4f4f4}span.expClpFlt img{padding:8px 11px 11px 11px}
|
4
dist/tablefilter/style/tablefilter.css
vendored
4
dist/tablefilter/style/tablefilter.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px solid #ccc;border-top:none;border-right:none;border-bottom:none;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-left:1px solid #fff;border-top:1px solid #fff;color:#333}table.TF td{border-bottom:1px dotted #999;padding:5px}.fltrow{background-color:#ebecee !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #666 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #999 !important}input.flt{width:99% !important}.inf{height:$min-height;background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important}input.reset{background:transparent url("images/btn_eraser.gif") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;}.nextPage:hover{background:transparent url("images/btn_over_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important;}.previousPage:hover{background:transparent url("images/btn_over_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;}.firstPage:hover{background:transparent url("images/btn_over_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;}.lastPage:hover{background:transparent url("images/btn_over_last_page.gif") center center no-repeat !important}div.grd_Cont{background-color:#ebecee !important;border:1px solid #ccc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#d5d5d5}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important;}div.grd_headTblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #999 !important}.grd_inf{background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important;border-top:1px solid #d0d0d0 !important}.loader{border:1px solid #999}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#fff}.odd{background-color:#d5d5d5}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#999 !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px dotted #81963b;border-top:none;border-right:0;border-bottom:none;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x;border-bottom:0;border-right:1px dotted #d0d0d0;border-left:0;border-top:0;color:#fff}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px}.fltrow{background-color:#81963b !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #687830 !important}input.flt{width:99% !important}.inf{background:#d8d8d8;height:$min-height}input.reset{width:53px;background:transparent url("images/btn_filter.png") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important}div.grd_Cont{background:#81963b url("images/bg_headers.jpg") left top repeat-x !important;border:1px solid #ccc !important;padding:0 1px 1px 1px !important;}div.grd_Cont .even{background-color:#bccd83}div.grd_Cont .odd{background-color:#fff}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important;}div.grd_tblCont table td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b}div.grd_tblCont table th,div.grd_headTblCont table th{background:transparent url("images/bg_headers.jpg") 0 0 repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;padding:0 4px 0 4px !important;color:#fff !important;height:35px !important}div.grd_headTblCont table td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;background-color:#81963b !important;padding:1px 3px 1px 3px !important}.grd_inf{background-color:#d8d8d8;border-top:1px solid #d0d0d0 !important}.loader{border:0 !important;background:#81963b !important}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#bccd83}.odd{background-color:#fff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#81963b !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.65 by Max Guglielmi
|
||||
* build date: 2016-09-07T11:33:04.352Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-10T14:01:17.213Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{padding:0;color:#000;border-right:1px solid #a4bed4;border-top:1px solid #a4bed4;border-left:1px solid #a4bed4;border-bottom:0;}table.TF th{margin:0;color:inherit;background:#d1e5fe url("images/bg_skyblue.gif") 0 0 repeat-x;border-color:#fdfdfd #a4bed4 #a4bed4 #fdfdfd;border-width:1px;border-style:solid}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid #a4bed4;border-left:0;border-top:0;border-right:0}.fltrow{background-color:#d1e5fe !important;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4 !important}input.flt{width:99% !important}.inf{background-color:#e3efff !important;border:1px solid #a4bed4;height:$min-height;color:#004a6f}div.tot,div.status{border-right:0 !important}.helpBtn:hover{background-color:transparent}input.reset{background:transparent url("images/icn_clear_filters.png") center center no-repeat !important}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.nextPage:hover{background:#ffe4ab url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#ffe4ab url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#ffe4ab url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#ffe4ab url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.activeHeader{background:#ffe4ab !important;border:1px solid #ffb552 !important;color:inherit !important}div.grd_Cont{background-color:#d9eaed !important;border:1px solid #9cc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#e3efff}div.grd_headTblCont{background-color:#d9eaed !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#d9eaed url("images/bg_skyblue.gif") left top repeat-x;border-bottom:1px solid #a4bed4;border-right:1px solid #a4bed4 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #a4bed4 !important;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:#cce2fe;color:#004a6f;border-top:1px solid #9cc !important;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#2d8eef;border:1px solid #cce2fe;border-radius:5px}.even{background-color:#fff}.odd{background-color:#e3efff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ffdc61 !important;color:inherit}.ezSelectedRow{background-color:#ffe4ab !important;color:inherit}.ezActiveCell{background-color:#fff !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#fff !important;font-weight:bold;color:#000 !important}
|
12
dist/tablefilter/tablefilter.js
vendored
12
dist/tablefilter/tablefilter.js
vendored
File diff suppressed because one or more lines are too long
8
dist/tablefilter/tf-1.js
vendored
8
dist/tablefilter/tf-1.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tablefilter",
|
||||
"version": "0.2.65",
|
||||
"version": "0.3.0",
|
||||
"description": "A Javascript library making HTML tables filterable and a bit more",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
|
34
src/const.js
34
src/const.js
|
@ -73,6 +73,40 @@ export const HEADER_TAG = 'TH';
|
|||
*/
|
||||
export const CELL_TAG = 'TD';
|
||||
|
||||
/**
|
||||
* Data types
|
||||
*/
|
||||
|
||||
/**
|
||||
* String
|
||||
* @type {String}
|
||||
*/
|
||||
export const STRING = 'string';
|
||||
|
||||
/**
|
||||
* Number
|
||||
* @type {String}
|
||||
*/
|
||||
export const NUMBER = 'number';
|
||||
|
||||
/**
|
||||
* Formatted number
|
||||
* @type {String}
|
||||
*/
|
||||
export const FORMATTED_NUMBER = 'formatted-number';
|
||||
|
||||
/**
|
||||
* Formatted number
|
||||
* @type {String}
|
||||
*/
|
||||
export const FORMATTED_NUMBER_EU = 'formatted-number-eu';
|
||||
|
||||
/**
|
||||
*IP address
|
||||
* @type {String}
|
||||
*/
|
||||
export const IP_ADDRESS = 'ipaddress';
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*/
|
||||
|
|
|
@ -3,8 +3,11 @@ import {isArray, isFn, isUndef} from '../../types';
|
|||
import {createElm, elm, getText, tag} from '../../dom';
|
||||
import {addEvt} from '../../event';
|
||||
import {formatDate} from '../../date';
|
||||
import {removeNbFormat} from '../../helpers';
|
||||
import {NONE, CELL_TAG, HEADER_TAG} from '../../const';
|
||||
import {unformat as unformatNb} from '../../number';
|
||||
import {
|
||||
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, FORMATTED_NUMBER,
|
||||
FORMATTED_NUMBER_EU, IP_ADDRESS
|
||||
} from '../../const';
|
||||
|
||||
/**
|
||||
* SortableTable Adapter module
|
||||
|
@ -401,8 +404,9 @@ export default class AdapterSortableTable extends Feature {
|
|||
colType = 'None';
|
||||
}
|
||||
} else { // resolve column types
|
||||
if (tf.hasColNbFormat && tf.colNbFormat[i] !== null) {
|
||||
colType = tf.colNbFormat[i].toLowerCase();
|
||||
if (tf.hasType(i, [NUMBER, FORMATTED_NUMBER,
|
||||
FORMATTED_NUMBER_EU, IP_ADDRESS])) {
|
||||
colType = tf.colTypes[i].toLowerCase();
|
||||
} else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
||||
colType = tf.colDateType[i].toLowerCase() + 'date';
|
||||
} else {
|
||||
|
@ -415,17 +419,17 @@ export default class AdapterSortableTable extends Feature {
|
|||
//Public TF method to add sort type
|
||||
|
||||
//Custom sort types
|
||||
this.addSortType('number', Number);
|
||||
this.addSortType(NUMBER, Number);
|
||||
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
||||
this.addSortType('date', SortableTable.toDate);
|
||||
this.addSortType('string');
|
||||
this.addSortType('us', usNumberConverter);
|
||||
this.addSortType('eu', euNumberConverter);
|
||||
this.addSortType(STRING);
|
||||
this.addSortType(FORMATTED_NUMBER, usNumberConverter);
|
||||
this.addSortType(FORMATTED_NUMBER_EU, euNumberConverter);
|
||||
this.addSortType('dmydate', dmyDateConverter);
|
||||
this.addSortType('ymddate', ymdDateConverter);
|
||||
this.addSortType('mdydate', mdyDateConverter);
|
||||
this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
||||
this.addSortType('ipaddress', ipAddress, sortIP);
|
||||
this.addSortType(IP_ADDRESS, ipAddress, sortIP);
|
||||
|
||||
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
||||
|
||||
|
@ -483,10 +487,10 @@ export default class AdapterSortableTable extends Feature {
|
|||
|
||||
//Converters
|
||||
function usNumberConverter(s) {
|
||||
return removeNbFormat(s, 'us');
|
||||
return unformatNb(s, FORMATTED_NUMBER);
|
||||
}
|
||||
function euNumberConverter(s) {
|
||||
return removeNbFormat(s, 'eu');
|
||||
return unformatNb(s, FORMATTED_NUMBER_EU);
|
||||
}
|
||||
function dateConverter(s, format) {
|
||||
return formatDate(s, format);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* Misc helpers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a unformatted number
|
||||
* @param {String} Formatted number
|
||||
* @param {String} Format type, currently 'us' or 'eu'
|
||||
* @return {String} Unformatted number
|
||||
*/
|
||||
export const removeNbFormat = (data, format = 'us') => {
|
||||
let n = data;
|
||||
if (format.toLowerCase() === 'us') {
|
||||
n = + n.replace(/[^\d\.-]/g, '');
|
||||
} else {
|
||||
n = + n.replace(/[^\d\,-]/g, '').replace(',', '.');
|
||||
}
|
||||
return n;
|
||||
}
|
30
src/number.js
Normal file
30
src/number.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import {isNumber} from './types';
|
||||
import {FORMATTED_NUMBER} from './const';
|
||||
|
||||
/**
|
||||
* Returns a number for a formatted number
|
||||
* @param {String} Formatted number
|
||||
* @param {String} Format type, currently 'formatted-number' or
|
||||
* 'formatted-number-eu'
|
||||
* @return {Number} Unformatted number
|
||||
*/
|
||||
export const unformat = (value, format = FORMATTED_NUMBER) => {
|
||||
// Return the value as-is if it's already a number
|
||||
if (isNumber(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Build regex to strip out everything except digits, decimal point and
|
||||
// minus sign
|
||||
let decimal = format !== FORMATTED_NUMBER ? ',' : '.';
|
||||
let regex = new RegExp('[^0-9-' + decimal + ']', ['g']);
|
||||
let unformatted = parseFloat(
|
||||
('' + value)
|
||||
.replace(/\((.*)\)/, '-$1') // replace bracketed values with negatives
|
||||
.replace(regex, '') // strip out any cruft
|
||||
.replace(decimal, '.') // make sure decimal point is standard
|
||||
);
|
||||
|
||||
// This will fail silently
|
||||
return !isNaN(unformatted) ? unformatted : 0;
|
||||
}
|
|
@ -8,7 +8,7 @@ import {isEmpty as isEmptyString} from './string';
|
|||
import {isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef}
|
||||
from './types';
|
||||
import {formatDate, isValidDate} from './date';
|
||||
import {removeNbFormat} from './helpers';
|
||||
import {unformat as unformatNb} from './number'
|
||||
|
||||
import {root} from './root';
|
||||
import {Emitter} from './emitter';
|
||||
|
@ -30,7 +30,7 @@ import {State} from './modules/state';
|
|||
import {
|
||||
INPUT, SELECT, MULTIPLE, CHECKLIST, NONE,
|
||||
ENTER_KEY, TAB_KEY, ESC_KEY, UP_ARROW_KEY, DOWN_ARROW_KEY,
|
||||
CELL_TAG, AUTO_FILTER_DELAY
|
||||
CELL_TAG, AUTO_FILTER_DELAY, NUMBER, FORMATTED_NUMBER, FORMATTED_NUMBER_EU
|
||||
} from './const';
|
||||
|
||||
let doc = root.document;
|
||||
|
@ -856,21 +856,6 @@ export class TableFilter {
|
|||
*/
|
||||
this.decimalSeparator = f.decimal_separator || '.';
|
||||
|
||||
/**
|
||||
* Determine whether table has columns with numeric formats
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasColNbFormat = isArray(f.col_number_format);
|
||||
|
||||
/**
|
||||
* Define numeric format on a column basis, two possible values 'EU' and
|
||||
* 'US', ie:
|
||||
* col_number_format : [null, 'US', 'EU', null]
|
||||
* @type {Array}
|
||||
*/
|
||||
this.colNbFormat = this.hasColNbFormat ? f.col_number_format : null;
|
||||
|
||||
/**
|
||||
* Determine whether table has columns with date types
|
||||
* @type {Boolean}
|
||||
|
@ -886,6 +871,23 @@ export class TableFilter {
|
|||
*/
|
||||
this.colDateType = this.hasColDateType ? f.col_date_type : null;
|
||||
|
||||
/**
|
||||
* Determine whether table has columns data types
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasColTypes = isArray(f.col_types);
|
||||
|
||||
/**
|
||||
* Define data types on a column basis, possible values 'string',
|
||||
* 'number', 'formatted-number', 'formatted-number-eu', 'DMY', 'MDY',
|
||||
* 'YMD', 'DDMMMYYYY', 'ipaddress' ie:
|
||||
* col_types : ['formatted-number', 'DMY', 'MDY', 'YMD', null,
|
||||
* 'DDMMMYYYY']
|
||||
* @type {Array}
|
||||
*/
|
||||
this.colTypes = this.hasColTypes ? f.col_types : [];
|
||||
|
||||
/*** ids prefixes ***/
|
||||
/**
|
||||
* Main prefix
|
||||
|
@ -1862,42 +1864,53 @@ export class TableFilter {
|
|||
}
|
||||
|
||||
else {
|
||||
//first numbers need to be formated
|
||||
if (this.hasColNbFormat && this.colNbFormat[j]) {
|
||||
numCellData = removeNbFormat(cellData, this.colNbFormat[j]);
|
||||
nbFormat = this.colNbFormat[j];
|
||||
//first numbers need to be unformatted
|
||||
if (this.hasType(j, [NUMBER])) {
|
||||
numCellData = Number(cellData);
|
||||
}
|
||||
else if (this.hasType(j,
|
||||
[FORMATTED_NUMBER, FORMATTED_NUMBER_EU])) {
|
||||
numCellData = unformatNb(cellData, this.colTypes[j]);
|
||||
nbFormat = this.colTypes[j];
|
||||
} else {
|
||||
if (this.thousandsSeparator === ',' &&
|
||||
this.decimalSeparator === '.') {
|
||||
numCellData = removeNbFormat(cellData, 'us');
|
||||
nbFormat = 'us';
|
||||
nbFormat = FORMATTED_NUMBER;
|
||||
} else {
|
||||
numCellData = removeNbFormat(cellData, 'eu');
|
||||
nbFormat = 'eu';
|
||||
nbFormat = FORMATTED_NUMBER_EU;
|
||||
}
|
||||
numCellData = unformatNb(cellData, nbFormat);
|
||||
}
|
||||
|
||||
// first checks if there is any operator (<,>,<=,>=,!,*,=,{,},
|
||||
// rgx:)
|
||||
// lower equal
|
||||
if (hasLE) {
|
||||
occurence = numCellData <= removeNbFormat(
|
||||
sA.replace(re_le, ''), nbFormat);
|
||||
occurence = numCellData <= unformatNb(
|
||||
sA.replace(re_le, ''),
|
||||
nbFormat
|
||||
);
|
||||
}
|
||||
//greater equal
|
||||
else if (hasGE) {
|
||||
occurence = numCellData >= removeNbFormat(
|
||||
sA.replace(re_ge, ''), nbFormat);
|
||||
occurence = numCellData >= unformatNb(
|
||||
sA.replace(re_ge, ''),
|
||||
nbFormat
|
||||
);
|
||||
}
|
||||
//lower
|
||||
else if (hasLO) {
|
||||
occurence = numCellData < removeNbFormat(
|
||||
sA.replace(re_l, ''), nbFormat);
|
||||
occurence = numCellData < unformatNb(
|
||||
sA.replace(re_l, ''),
|
||||
nbFormat
|
||||
);
|
||||
}
|
||||
//greater
|
||||
else if (hasGR) {
|
||||
occurence = numCellData > removeNbFormat(
|
||||
sA.replace(re_g, ''), nbFormat);
|
||||
occurence = numCellData > unformatNb(
|
||||
sA.replace(re_g, ''),
|
||||
nbFormat
|
||||
);
|
||||
}
|
||||
//different
|
||||
else if (hasDF) {
|
||||
|
@ -1950,12 +1963,14 @@ export class TableFilter {
|
|||
} else {
|
||||
// If numeric type data, perform a strict equality test and
|
||||
// fallback to unformatted number string comparison
|
||||
if (numCellData && this.hasColNbFormat &&
|
||||
this.colNbFormat[j] && !this.singleSearchFlt) {
|
||||
// removeNbFormat can return 0 for strings which are not
|
||||
if (numCellData &&
|
||||
this.hasType(j,
|
||||
[NUMBER, FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) &&
|
||||
!this.singleSearchFlt) {
|
||||
// unformatNb can return 0 for strings which are not
|
||||
// formatted numbers, in that case return the original
|
||||
// string. TODO: handle this in removeNbFormat
|
||||
sA = removeNbFormat(sA, nbFormat) || sA;
|
||||
// string. TODO: handle this in unformatNb
|
||||
sA = unformatNb(sA, nbFormat) || sA;
|
||||
occurence = numCellData === sA ||
|
||||
contains(sA.toString(), numCellData.toString(),
|
||||
this.isExactMatch(j), this.caseSensitive);
|
||||
|
@ -2111,11 +2126,11 @@ export class TableFilter {
|
|||
if (j !== colIndex || row[i].style.display !== '') {
|
||||
continue;
|
||||
}
|
||||
let cellData = this.getCellData(cell[j]),
|
||||
nbFormat = this.colNbFormat ?
|
||||
this.colNbFormat[colIndex] : undefined,
|
||||
data = num ? removeNbFormat(cellData, nbFormat) :
|
||||
cellData;
|
||||
let cellData = this.getCellData(cell[j]);
|
||||
let nbFormat = this.hasType(colIndex,
|
||||
[FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) ?
|
||||
this.colTypes[colIndex] : undefined;
|
||||
let data = num ? unformatNb(cellData, nbFormat) : cellData;
|
||||
colValues.push(data);
|
||||
}
|
||||
}
|
||||
|
@ -2823,6 +2838,17 @@ export class TableFilter {
|
|||
return (nbRows - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the specified column has one of the passed types
|
||||
* @param {Number} colIndex Column index
|
||||
* @param {Array} [types=[]] List of column types
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
hasType(colIndex, types = []) {
|
||||
return this.hasColTypes &&
|
||||
types.indexOf(this.colTypes[colIndex]) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header DOM element for a given column index
|
||||
* @param {Number} colIndex Column index
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
<li>"," thousands separator and "." decimal separator for US$</li>
|
||||
</ul>
|
||||
<p>
|
||||
Use the <code>col_number_format</code> property to set numeric formats
|
||||
('EU', 'US' or 'IPADDRESS') and <code>col_date_type</code> to set date
|
||||
Use the <code>col_types</code> property to set numeric formats
|
||||
('formatted-number', 'formatted-number-eu' or 'ipaddress') and <code>col_date_type</code> to set date
|
||||
types.
|
||||
</p>
|
||||
|
||||
|
@ -75,11 +75,11 @@ var tfConfig = {
|
|||
btn_reset: true,
|
||||
loader: true,
|
||||
status_bar: true,
|
||||
col_number_format: [
|
||||
col_types: [
|
||||
null, null, null,
|
||||
'EU', 'US', null,
|
||||
'formatted-number-eu', 'formatted-number', null,
|
||||
null, null, null,
|
||||
'IpAddress'
|
||||
'ipaddress'
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
mark_active_columns: true,
|
||||
no_results_message: true,
|
||||
responsive: true,
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
'US', 'US', 'US',
|
||||
'US', 'US', 'US'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
custom_options: {
|
||||
cols:[3],
|
||||
|
|
|
@ -88,10 +88,10 @@ var tfConfig = {
|
|||
status: true,
|
||||
status_bar: true,
|
||||
status_bar_target_id: 'statusDiv',
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
'US', 'US', 'US',
|
||||
'US', 'US', 'US'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
display_all_text: " [ Show all ] ",
|
||||
col_0: "multiple",
|
||||
|
|
|
@ -22,9 +22,9 @@ var tfConfig = {
|
|||
base_path: '../dist/tablefilter/',
|
||||
filters_row_index: 2,
|
||||
headers_row_index: 1,
|
||||
col_number_format: [
|
||||
col_types: [
|
||||
null, null, null,
|
||||
'US', null, null, null
|
||||
'number', null, null, null
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
|
|
|
@ -40,10 +40,10 @@ var tfConfig = {
|
|||
col_0: 'multiple',
|
||||
col_1: 'select',
|
||||
col_2: 'checklist',
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
'US', 'US', 'US',
|
||||
'US', 'US', 'US'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
filters_row_index: 3,
|
||||
headers_row_index: 2,
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
status_bar: true,
|
||||
mark_active_columns: true,
|
||||
highlight_keywords: true,
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
'US', 'US', 'US',
|
||||
'US', 'US', 'US'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
custom_options: {
|
||||
cols:[3],
|
||||
|
|
|
@ -30,9 +30,9 @@ var tfConfig = {
|
|||
filters_row_index: 2,
|
||||
headers_row_index: 1,
|
||||
sort: true,
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
null, null, null
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'string', 'string', 'string'
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// TODO: add sort to test it with different column types
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_number_format: [
|
||||
col_types: [
|
||||
null, null, null,
|
||||
'EU', 'US', null,
|
||||
'formatted-number-eu', 'formatted-number', null,
|
||||
null, null, null,
|
||||
'IpAddress'
|
||||
],
|
||||
|
@ -21,7 +21,11 @@
|
|||
module('Sanity checks');
|
||||
test('Data types', function() {
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
deepEqual(tf.hasColNbFormat, true, 'Has number column types');
|
||||
deepEqual(
|
||||
tf.hasType(3, ['formatted-number-eu', 'formatted-number']) &&
|
||||
tf.hasType(4, ['formatted-number-eu', 'formatted-number']),
|
||||
true, 'Has number column types'
|
||||
);
|
||||
deepEqual(tf.hasColDateType, true, 'Has date column tyoes');
|
||||
});
|
||||
|
||||
|
@ -86,7 +90,7 @@
|
|||
deepEqual(tf.getValidRows(), [7], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted number', function() {
|
||||
test('Can filter a formatted number', function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
||||
|
@ -98,7 +102,7 @@
|
|||
deepEqual(tf.getValidRows(), [6], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted number column with a number', function() {
|
||||
test('Can filter a formatted number column with a number', function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
||||
|
@ -110,7 +114,7 @@
|
|||
deepEqual(tf.getValidRows(), [14], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted number column with a number without ' +
|
||||
test('Can filter a formatted number column with a number without ' +
|
||||
'thousands separator', function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
@ -123,7 +127,7 @@
|
|||
deepEqual(tf.getValidRows(), [13], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted number column with a number without ' +
|
||||
test('Can filter a formatted number column with a number without ' +
|
||||
'decimals', function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
@ -161,7 +165,7 @@
|
|||
deepEqual(tf.getValidRows(), [17], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted date column', function() {
|
||||
test('Can filter a formatted date column', function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
||||
|
@ -173,7 +177,7 @@
|
|||
deepEqual(tf.getValidRows(), [16], 'Expected rows');
|
||||
});
|
||||
|
||||
test('Can filter a US formatted date column with different date separator',
|
||||
test('Can filter a formatted date column with different date separator',
|
||||
function() {
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
|
|
|
@ -4,9 +4,9 @@ var tf = new TableFilter('demo', {
|
|||
null, null, 'ddmmmyyyy',
|
||||
null, null, null
|
||||
],
|
||||
col_number_format: [
|
||||
col_types: [
|
||||
null, null, null,
|
||||
null, null, 'US'
|
||||
null, null, 'formatted-number'
|
||||
]
|
||||
});
|
||||
tf.init();
|
||||
|
|
Loading…
Reference in a new issue