mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-21 07:05:30 +02:00
Merge pull request #304 from koalyptus/issue-231-col-types
Issue 231 col types
This commit is contained in:
commit
fedf365400
12
dist/starter.html
vendored
12
dist/starter.html
vendored
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>tablefilter v0.2.67 - Starter</title>
|
||||
<title>tablefilter v0.3.0 - Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>tablefilter v0.2.67</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.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* 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.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* 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.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* MIT License
|
||||
*/
|
||||
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* 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.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* 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.67 by Max Guglielmi
|
||||
* build date: 2016-09-22T03:56:31.918Z
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-10-03T05:58:32.902Z
|
||||
* 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}
|
15
dist/tablefilter/tablefilter.js
vendored
15
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
13
package.json
13
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tablefilter",
|
||||
"version": "0.2.67",
|
||||
"version": "0.3.0",
|
||||
"description": "A Javascript library making HTML tables filterable and a bit more",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
@ -28,12 +28,12 @@
|
|||
"tag": "next"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.14.0",
|
||||
"babel-core": "^6.17.0",
|
||||
"babel-eslint": "7.0.0",
|
||||
"babel-loader": "^6.2.5",
|
||||
"babel-preset-es2015": "^6.14.0",
|
||||
"babel-plugin-transform-es2015-classes": "^6.14.0",
|
||||
"clean-webpack-plugin": "^0.1.9",
|
||||
"babel-preset-es2015": "^6.16.0",
|
||||
"clean-webpack-plugin": "^0.1.11",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-babel": "^6.0.0",
|
||||
"grunt-contrib-clean": "^1.0.0",
|
||||
|
@ -45,10 +45,11 @@
|
|||
"grunt-esdoc": "^0.0.4",
|
||||
"grunt-eslint": "19.0.0",
|
||||
"grunt-gh-pages": "^2.0.0",
|
||||
"grunt-string-replace": "^1.3.0",
|
||||
"grunt-webpack": "^1.0.14",
|
||||
"grunt-string-replace": "^1.3.1",
|
||||
"grunt-webpack": "^1.0.16",
|
||||
"script-loader": "^0.7.0",
|
||||
"string-replace-webpack-plugin": "^0.0.3",
|
||||
"sugar-date": "2.0.0",
|
||||
"webpack": "^1.13.2",
|
||||
"webpack-dev-server": "^1.16.1"
|
||||
},
|
||||
|
|
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';
|
||||
|
||||
/**
|
||||
* Date
|
||||
* @type {String}
|
||||
*/
|
||||
export const DATE = 'date';
|
||||
|
||||
/**
|
||||
* IP address
|
||||
* @type {String}
|
||||
*/
|
||||
export const IP_ADDRESS = 'ipaddress';
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*/
|
||||
|
|
183
src/date.js
183
src/date.js
|
@ -1,183 +0,0 @@
|
|||
/**
|
||||
* Date utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Verifies passed formatted date string is valid
|
||||
* @param {String} dateStr Formatted date string
|
||||
* @param {String} format accepted formats: 'DMY', 'MDY', 'YMD', 'DDMMMYYYY'
|
||||
* @return {Boolean}
|
||||
*/
|
||||
export const isValidDate = (dateStr, format) => {
|
||||
if (!format) {
|
||||
format = 'DMY';
|
||||
}
|
||||
format = format.toUpperCase();
|
||||
if (format.length !== 3) {
|
||||
if (format === 'DDMMMYYYY') {
|
||||
let d = formatDate(dateStr, format);
|
||||
dateStr = d.getDate() + '/' + (d.getMonth() + 1) + '/' +
|
||||
d.getFullYear();
|
||||
format = 'DMY';
|
||||
}
|
||||
}
|
||||
if ((format.indexOf('M') === -1) || (format.indexOf('D') === -1) ||
|
||||
(format.indexOf('Y') === -1)) {
|
||||
format = 'DMY';
|
||||
}
|
||||
let reg1, reg2;
|
||||
// If the year is first
|
||||
if (format.substring(0, 1) === 'Y') {
|
||||
reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
|
||||
reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
|
||||
} else if (format.substring(1, 2) === 'Y') { // If the year is second
|
||||
reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/;
|
||||
reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/;
|
||||
} else { // The year must be third
|
||||
reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;
|
||||
reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
|
||||
}
|
||||
// If it doesn't conform to the right format (with either a 2 digit year
|
||||
// or 4 digit year), fail
|
||||
if (reg1.test(dateStr) === false && reg2.test(dateStr) === false) {
|
||||
return false;
|
||||
}
|
||||
// Split into 3 parts based on what the divider was
|
||||
let parts = dateStr.split(RegExp.$1);
|
||||
let mm, dd, yy;
|
||||
// Check to see if the 3 parts end up making a valid date
|
||||
if (format.substring(0, 1) === 'M') {
|
||||
mm = parts[0];
|
||||
} else if (format.substring(1, 2) === 'M') {
|
||||
mm = parts[1];
|
||||
} else {
|
||||
mm = parts[2];
|
||||
}
|
||||
if (format.substring(0, 1) === 'D') {
|
||||
dd = parts[0];
|
||||
} else if (format.substring(1, 2) === 'D') {
|
||||
dd = parts[1];
|
||||
} else {
|
||||
dd = parts[2];
|
||||
}
|
||||
if (format.substring(0, 1) === 'Y') {
|
||||
yy = parts[0];
|
||||
} else if (format.substring(1, 2) === 'Y') {
|
||||
yy = parts[1];
|
||||
} else {
|
||||
yy = parts[2];
|
||||
}
|
||||
if (parseInt(yy, 10) <= 50) {
|
||||
yy = (parseInt(yy, 10) + 2000).toString();
|
||||
}
|
||||
if (parseInt(yy, 10) <= 99) {
|
||||
yy = (parseInt(yy, 10) + 1900).toString();
|
||||
}
|
||||
let dt = new Date(
|
||||
parseInt(yy, 10), parseInt(mm, 10) - 1, parseInt(dd, 10),
|
||||
0, 0, 0, 0);
|
||||
if (parseInt(dd, 10) !== dt.getDate()) {
|
||||
return false;
|
||||
}
|
||||
if (parseInt(mm, 10) - 1 !== dt.getMonth()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts formatted date into a Date object
|
||||
* @param {String} dateStr Formatted date string
|
||||
* @param {String} format accepted formats: 'DMY', 'MDY', 'YMD', 'DDMMMYYYY'
|
||||
* @return {Object} date object
|
||||
*/
|
||||
export const formatDate = (dateStr, formatStr) => {
|
||||
if (!formatStr) {
|
||||
formatStr = 'DMY';
|
||||
}
|
||||
if (!dateStr || dateStr === '') {
|
||||
return new Date(1001, 0, 1);
|
||||
}
|
||||
let oDate;
|
||||
let parts;
|
||||
|
||||
switch (formatStr.toUpperCase()) {
|
||||
case 'DDMMMYYYY':
|
||||
parts = dateStr.replace(/[- \/.]/g, ' ').split(' ');
|
||||
oDate = new Date(y2kDate(parts[2]), mmm2mm(parts[1]) - 1, parts[0]);
|
||||
break;
|
||||
case 'DMY':
|
||||
/* eslint-disable */
|
||||
parts = dateStr.replace(
|
||||
/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, '$1 $3 $5').split(' ');
|
||||
oDate = new Date(y2kDate(parts[2]), parts[1] - 1, parts[0]);
|
||||
/* eslint-enable */
|
||||
break;
|
||||
case 'MDY':
|
||||
/* eslint-disable */
|
||||
parts = dateStr.replace(
|
||||
/^(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])([- \/.])((\d\d)?\d\d)$/, '$1 $3 $5').split(' ');
|
||||
oDate = new Date(y2kDate(parts[2]), parts[0] - 1, parts[1]);
|
||||
/* eslint-enable */
|
||||
break;
|
||||
case 'YMD':
|
||||
/* eslint-disable */
|
||||
parts = dateStr.replace(/^((\d\d)?\d\d)([- \/.])(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])$/, '$1 $4 $6').split(' ');
|
||||
oDate = new Date(y2kDate(parts[0]), parts[1] - 1, parts[2]);
|
||||
/* eslint-enable */
|
||||
break;
|
||||
default: //in case format is not correct
|
||||
/* eslint-disable */
|
||||
parts = dateStr.replace(/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, '$1 $3 $5').split(' ');
|
||||
oDate = new Date(y2kDate(parts[2]), parts[1] - 1, parts[0]);
|
||||
/* eslint-enable */
|
||||
break;
|
||||
}
|
||||
return oDate;
|
||||
}
|
||||
|
||||
function y2kDate(yr) {
|
||||
if (yr === undefined) {
|
||||
return 0;
|
||||
}
|
||||
if (yr.length > 2) {
|
||||
return yr;
|
||||
}
|
||||
let y;
|
||||
//>50 belong to 1900
|
||||
if (yr <= 99 && yr > 50) {
|
||||
y = '19' + yr;
|
||||
}
|
||||
//<50 belong to 2000
|
||||
if (yr < 50 || yr === '00') {
|
||||
y = '20' + yr;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
function mmm2mm(mmm) {
|
||||
if (mmm === undefined) {
|
||||
return 0;
|
||||
}
|
||||
let mondigit;
|
||||
let MONTH_NAMES = [
|
||||
'january', 'february', 'march', 'april', 'may', 'june', 'july',
|
||||
'august', 'september', 'october', 'november', 'december',
|
||||
'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct',
|
||||
'nov', 'dec'
|
||||
];
|
||||
for (let m_i = 0; m_i < MONTH_NAMES.length; m_i++) {
|
||||
let month_name = MONTH_NAMES[m_i];
|
||||
if (mmm.toLowerCase() === month_name) {
|
||||
mondigit = m_i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mondigit > 11 || mondigit < 23) {
|
||||
mondigit = mondigit - 12;
|
||||
}
|
||||
if (mondigit < 1 || mondigit > 12) {
|
||||
return 0;
|
||||
}
|
||||
return mondigit;
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
import {Feature} from '../../feature';
|
||||
import {isArray, isFn, isUndef} from '../../types';
|
||||
import {isArray, isFn, isUndef, isObj} 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 {parse as parseNb} from '../../number';
|
||||
import {
|
||||
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
|
||||
IP_ADDRESS
|
||||
} from '../../const';
|
||||
|
||||
/**
|
||||
* SortableTable Adapter module
|
||||
|
@ -42,7 +44,7 @@ export default class AdapterSortableTable extends Feature {
|
|||
* List of sort type per column basis
|
||||
* @type {Array}
|
||||
*/
|
||||
this.sortTypes = isArray(opts.types) ? opts.types : [];
|
||||
this.sortTypes = isArray(opts.types) ? opts.types : tf.colTypes;
|
||||
|
||||
/**
|
||||
* Column to be sorted at initialization, ie:
|
||||
|
@ -146,10 +148,14 @@ export default class AdapterSortableTable extends Feature {
|
|||
throw new Error('SortableTable class not found.');
|
||||
}
|
||||
|
||||
// Add any date format if needed
|
||||
let dateType = tf.feature('dateType');
|
||||
dateType.addConfigFormats(this.sortTypes);
|
||||
|
||||
this.overrideSortableTable();
|
||||
this.setSortTypes();
|
||||
|
||||
//Column sort at start
|
||||
// Column sort at start
|
||||
let sortColAtStart = adpt.sortColAtStart;
|
||||
if (sortColAtStart) {
|
||||
this.stt.sort(sortColAtStart[0], sortColAtStart[1]);
|
||||
|
@ -378,9 +384,10 @@ export default class AdapterSortableTable extends Feature {
|
|||
/**
|
||||
* Adds a sort type
|
||||
*/
|
||||
addSortType() {
|
||||
var args = arguments;
|
||||
SortableTable.prototype.addSortType(args[0], args[1], args[2], args[3]);
|
||||
addSortType(...args) {
|
||||
// Extract the arguments
|
||||
let [id, caster, sorter] = args;
|
||||
SortableTable.prototype.addSortType(id, caster, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,20 +401,32 @@ export default class AdapterSortableTable extends Feature {
|
|||
|
||||
for (let i = 0; i < tf.nbCells; i++) {
|
||||
let colType;
|
||||
|
||||
if (sortTypes[i]) {
|
||||
colType = sortTypes[i].toLowerCase();
|
||||
if (colType === NONE) {
|
||||
colType = 'None';
|
||||
}
|
||||
} else { // resolve column types
|
||||
if (tf.hasColNbFormat && tf.colNbFormat[i] !== null) {
|
||||
colType = tf.colNbFormat[i].toLowerCase();
|
||||
} else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
||||
colType = tf.colDateType[i].toLowerCase() + 'date';
|
||||
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 = 'String';
|
||||
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);
|
||||
}
|
||||
|
@ -415,17 +434,9 @@ export default class AdapterSortableTable extends Feature {
|
|||
//Public TF method to add sort type
|
||||
|
||||
//Custom sort types
|
||||
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('dmydate', dmyDateConverter);
|
||||
this.addSortType('ymddate', ymdDateConverter);
|
||||
this.addSortType('mdydate', mdyDateConverter);
|
||||
this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
||||
this.addSortType('ipaddress', ipAddress, sortIP);
|
||||
this.addSortType(STRING);
|
||||
this.addSortType(IP_ADDRESS, ipAddress, sortIP);
|
||||
|
||||
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
||||
|
||||
|
@ -453,6 +464,27 @@ export default class AdapterSortableTable extends Feature {
|
|||
}
|
||||
}
|
||||
|
||||
_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) => {
|
||||
return dateType.parse(value, locale);
|
||||
});
|
||||
return colType;
|
||||
}
|
||||
|
||||
_addNumberType(colIndex, decimal) {
|
||||
let colType = `${FORMATTED_NUMBER}${decimal === '.' ? '' : '-custom'}`;
|
||||
|
||||
this.addSortType(colType, (value) => {
|
||||
return parseNb(value, decimal);
|
||||
});
|
||||
return colType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove extension
|
||||
*/
|
||||
|
@ -464,7 +496,6 @@ export default class AdapterSortableTable extends Feature {
|
|||
this.emitter.off(['sort'],
|
||||
(tf, colIdx, desc) => this.sortByColumnIndex(colIdx, desc));
|
||||
this.sorted = false;
|
||||
this.initialized = false;
|
||||
this.stt.destroy();
|
||||
|
||||
let ids = tf.getFiltersId();
|
||||
|
@ -482,28 +513,6 @@ export default class AdapterSortableTable extends Feature {
|
|||
}
|
||||
|
||||
//Converters
|
||||
function usNumberConverter(s) {
|
||||
return removeNbFormat(s, 'us');
|
||||
}
|
||||
function euNumberConverter(s) {
|
||||
return removeNbFormat(s, 'eu');
|
||||
}
|
||||
function dateConverter(s, format) {
|
||||
return formatDate(s, format);
|
||||
}
|
||||
function dmyDateConverter(s) {
|
||||
return dateConverter(s, 'DMY');
|
||||
}
|
||||
function mdyDateConverter(s) {
|
||||
return dateConverter(s, 'MDY');
|
||||
}
|
||||
function ymdDateConverter(s) {
|
||||
return dateConverter(s, 'YMD');
|
||||
}
|
||||
function ddmmmyyyyDateConverter(s) {
|
||||
return dateConverter(s, 'DDMMMYYYY');
|
||||
}
|
||||
|
||||
function ipAddress(value) {
|
||||
let vals = value.split('.');
|
||||
for (let x in vals) {
|
||||
|
|
|
@ -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;
|
||||
}
|
132
src/modules/dateType.js
Normal file
132
src/modules/dateType.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
import {Date as SugarDate} from 'sugar-date';
|
||||
import 'sugar-date/locales';
|
||||
import {Feature} from '../feature';
|
||||
import {isObj, isArray} from '../types';
|
||||
import {DATE} from '../const';
|
||||
|
||||
/**
|
||||
* Wrapper for Sugar Date module providing datetime helpers and locales
|
||||
* @export
|
||||
* @class DateType
|
||||
*/
|
||||
export class DateType extends Feature {
|
||||
|
||||
/**
|
||||
* Creates an instance of DateType
|
||||
* @param {TableFilter} tf TableFilter instance
|
||||
*/
|
||||
constructor(tf) {
|
||||
super(tf, 'dateType');
|
||||
|
||||
/**
|
||||
* Global locale
|
||||
* @type {String}
|
||||
*/
|
||||
this.locale = tf.locale;
|
||||
|
||||
/**
|
||||
* Sugar Date instance
|
||||
* @type {Object}
|
||||
*/
|
||||
this.datetime = SugarDate;
|
||||
|
||||
this.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DateType instance
|
||||
*/
|
||||
init() {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set global locale
|
||||
this.datetime.setLocale(this.locale);
|
||||
|
||||
// Add formats from column types configuration if any
|
||||
this.addConfigFormats(this.tf.colTypes);
|
||||
|
||||
// Broadcast date-type initialization
|
||||
this.emitter.emit('date-type-initialized', this.tf, this);
|
||||
|
||||
/** @inherited */
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string representation of a date for a specified locale and return
|
||||
* a date object
|
||||
* @param {String} dateStr String representation of a date
|
||||
* @param {String} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Date}
|
||||
*/
|
||||
parse(dateStr, localeCode) {
|
||||
return this.datetime.create(dateStr, localeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check string representation of a date for a specified locale is valid
|
||||
* @param {any} dateStr String representation of a date
|
||||
* @param {any} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isValid(dateStr, localeCode) {
|
||||
return this.datetime.isValid(this.parse(dateStr, localeCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type object of a specified column as per configuration or
|
||||
* passed collection
|
||||
* @param {Number} colIndex Column index
|
||||
* @param {Array} types Collection of column types, optional
|
||||
* @returns {Object}
|
||||
*/
|
||||
getOptions(colIndex, types) {
|
||||
types = types || this.tf.colTypes;
|
||||
let colType = types[colIndex];
|
||||
return isObj(colType) ? colType : {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add date time format(s) to a locale as specified by the passed
|
||||
* collection of column types, ie:
|
||||
* [
|
||||
* 'string',
|
||||
* 'number',
|
||||
* { type: 'date', locale: 'en', format: ['{dd}/{MM}/{yyyy}']}
|
||||
* ]
|
||||
*
|
||||
* @param {Array} [types=[]] Collection of column types
|
||||
*/
|
||||
addConfigFormats(types=[]) {
|
||||
types.forEach((type, idx) => {
|
||||
let options = this.getOptions(idx, types);
|
||||
if (options.type === DATE && options.hasOwnProperty('format')) {
|
||||
let locale = this.datetime.getLocale(
|
||||
options.locale || this.locale
|
||||
);
|
||||
if (isArray(options.format)) {
|
||||
options.format.forEach((format) => {
|
||||
locale.addFormat(format);
|
||||
});
|
||||
} else {
|
||||
locale.addFormat(options.format);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove DateType instance
|
||||
*/
|
||||
destroy() {
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: remove added formats
|
||||
|
||||
this.initialized = false;
|
||||
}
|
||||
}
|
|
@ -162,13 +162,15 @@ export class PopupFilter extends Feature {
|
|||
let tf = this.tf;
|
||||
|
||||
// Override headers row index if no grouped headers
|
||||
// TODO: Prevent the filters row to simplify headers row index adjusting
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.headersRow <= 1 && isNaN(tf.config().headers_row_index)) {
|
||||
tf.headersRow = 0;
|
||||
}
|
||||
|
||||
// Adjust headers row index for grid-layout mode
|
||||
// TODO: Prevent the filters row to simplify headers row index adjusting
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.gridLayout) {
|
||||
tf.headersRow--;
|
||||
this.buildIcons();
|
||||
|
@ -204,8 +206,8 @@ export class PopupFilter extends Feature {
|
|||
buildIcons() {
|
||||
let tf = this.tf;
|
||||
|
||||
// Filters row is added to the DOM, adjust headers row index
|
||||
// TODO: Prevent the filters row to simplify headers row index adjusting
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
tf.headersRow++;
|
||||
|
||||
for (let i = 0; i < tf.nbCells; i++) {
|
||||
|
|
29
src/number.js
Normal file
29
src/number.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import {isNumber} from './types';
|
||||
|
||||
/**
|
||||
* Takes a string, removes all formatting/cruft and returns the raw float value
|
||||
* @param {String} Formatted number
|
||||
* @param {String} Decimal type '.' or ','
|
||||
* @return {Number} Unformatted number
|
||||
*
|
||||
* https://github.com/openexchangerates/accounting.js/blob/master/accounting.js
|
||||
*/
|
||||
export const parse = (value, decimal = '.') => {
|
||||
// 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 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;
|
||||
}
|
|
@ -5,10 +5,10 @@ import {
|
|||
} from './dom';
|
||||
import {contains, matchCase, rgxEsc, trim} from './string';
|
||||
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 {
|
||||
isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef
|
||||
} from './types';
|
||||
import {parse as parseNb} from './number'
|
||||
|
||||
import {root} from './root';
|
||||
import {Emitter} from './emitter';
|
||||
|
@ -26,11 +26,12 @@ import {Help} from './modules/help';
|
|||
import {AlternateRows} from './modules/alternateRows';
|
||||
import {NoResults} from './modules/noResults';
|
||||
import {State} from './modules/state';
|
||||
import {DateType} from './modules/dateType';
|
||||
|
||||
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, DATE, FORMATTED_NUMBER
|
||||
} from './const';
|
||||
|
||||
let doc = root.document;
|
||||
|
@ -838,11 +839,13 @@ export class TableFilter {
|
|||
this.state = isObj(f.state) || Boolean(f.state);
|
||||
|
||||
/*** data types ***/
|
||||
|
||||
/**
|
||||
* Define default date type (DMY)
|
||||
* Define default locale, default to 'en' as per Sugar Date module:
|
||||
* https://sugarjs.com/docs/#/DateLocales
|
||||
* @type {String}
|
||||
*/
|
||||
this.defaultDateType = f.default_date_type || 'DMY';
|
||||
this.locale = f.locale || 'en';
|
||||
|
||||
/**
|
||||
* Define thousands separator ',' or '.', defaults to ','
|
||||
|
@ -857,34 +860,27 @@ export class TableFilter {
|
|||
this.decimalSeparator = f.decimal_separator || '.';
|
||||
|
||||
/**
|
||||
* Determine whether table has columns with numeric formats
|
||||
* Determine whether table has columns data types
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasColNbFormat = isArray(f.col_number_format);
|
||||
this.hasColTypes = isArray(f.col_types);
|
||||
|
||||
/**
|
||||
* Define numeric format on a column basis, two possible values 'EU' and
|
||||
* 'US', ie:
|
||||
* col_number_format : [null, 'US', 'EU', null]
|
||||
* Define data types on a column basis, possible values 'string',
|
||||
* 'number', 'formatted-number', 'date', 'ipaddress' ie:
|
||||
* col_types : [
|
||||
* 'string', 'date', 'number',
|
||||
* { type: 'formatted-number', decimal: ',', thousands: '.' },
|
||||
* { type: 'date', locale: 'en-gb' },
|
||||
* { type: 'date', format: ['{dd}-{months}-{yyyy|yy}'] }
|
||||
* ]
|
||||
*
|
||||
* Refer to https://sugarjs.com/docs/#/DateParsing for exhaustive
|
||||
* information on date parsing formats supported by Sugar Date
|
||||
* @type {Array}
|
||||
*/
|
||||
this.colNbFormat = this.hasColNbFormat ? f.col_number_format : null;
|
||||
|
||||
/**
|
||||
* Determine whether table has columns with date types
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasColDateType = isArray(f.col_date_type);
|
||||
|
||||
/**
|
||||
* Define date format on a column basis, possible values 'DMY', 'MDY',
|
||||
* 'YMD', 'DDMMMYYYY', ie:
|
||||
* col_date_type : [null, 'DMY', 'MDY', 'YMD', null, 'DDMMMYYYY']
|
||||
* @type {Array}
|
||||
*/
|
||||
this.colDateType = this.hasColDateType ? f.col_date_type : null;
|
||||
this.colTypes = this.hasColTypes ? f.col_types : [];
|
||||
|
||||
/*** ids prefixes ***/
|
||||
/**
|
||||
|
@ -1018,6 +1014,12 @@ export class TableFilter {
|
|||
this.loadThemes();
|
||||
}
|
||||
|
||||
// Instanciate sugar date wrapper
|
||||
if (!Mod.dateType) {
|
||||
Mod.dateType = new DateType(this);
|
||||
Mod.dateType.init();
|
||||
}
|
||||
|
||||
// Instantiate help feature and initialise only if set true
|
||||
if (!Mod.help) {
|
||||
Mod.help = new Help(this);
|
||||
|
@ -1283,6 +1285,9 @@ export class TableFilter {
|
|||
* Insert filters row at initialization
|
||||
*/
|
||||
_insertFiltersRow() {
|
||||
// TODO: prevent filters row generation for popup filters too,
|
||||
// to reduce and simplify headers row index adjusting across lib modules
|
||||
// (GridLayout, PopupFilter etc)
|
||||
if (this.gridLayout) {
|
||||
return;
|
||||
}
|
||||
|
@ -1738,8 +1743,8 @@ export class TableFilter {
|
|||
// search args re-init
|
||||
let searchArgs = this.getFiltersValue();
|
||||
|
||||
let numCellData;
|
||||
let nbFormat;
|
||||
let numData;
|
||||
let decimal = this.decimalSeparator;
|
||||
let re_le = new RegExp(this.leOperator),
|
||||
re_ge = new RegExp(this.geOperator),
|
||||
re_l = new RegExp(this.lwOperator),
|
||||
|
@ -1775,12 +1780,10 @@ export class TableFilter {
|
|||
}
|
||||
|
||||
//looks for search argument in current row
|
||||
function hasArg(sA, cellData, j) {
|
||||
function hasArg(sA, cellData, colIdx) {
|
||||
sA = matchCase(sA, this.caseSensitive);
|
||||
|
||||
let occurence;
|
||||
let dtType = this.hasColDateType ?
|
||||
this.colDateType[j] : this.defaultDateType;
|
||||
let occurence = false;
|
||||
|
||||
//Search arg operator tests
|
||||
let hasLO = re_l.test(sA),
|
||||
|
@ -1797,46 +1800,59 @@ export class TableFilter {
|
|||
hasNM = (re_nm === sA),
|
||||
hasRE = re_re.test(sA);
|
||||
|
||||
//Search arg dates tests
|
||||
let isLDate = hasLO && isValidDate(sA.replace(re_l, ''), dtType);
|
||||
let isLEDate = hasLE && isValidDate(sA.replace(re_le, ''), dtType);
|
||||
let isGDate = hasGR && isValidDate(sA.replace(re_g, ''), dtType);
|
||||
let isGEDate = hasGE && isValidDate(sA.replace(re_ge, ''), dtType);
|
||||
let isDFDate = hasDF && isValidDate(sA.replace(re_d, ''), dtType);
|
||||
let isEQDate = hasEQ && isValidDate(sA.replace(re_eq, ''), dtType);
|
||||
// Check for dates or resolve date type
|
||||
if (this.hasType(colIdx, [DATE])) {
|
||||
let dte1, dte2;
|
||||
|
||||
let dateType = this.Mod.dateType;
|
||||
let isValidDate = dateType.isValid.bind(dateType);
|
||||
let parseDate = dateType.parse.bind(dateType);
|
||||
let locale = dateType.getOptions(colIdx).locale || this.locale;
|
||||
|
||||
// Search arg dates tests
|
||||
let isLDate = hasLO &&
|
||||
isValidDate(sA.replace(re_l, ''), locale);
|
||||
let isLEDate = hasLE &&
|
||||
isValidDate(sA.replace(re_le, ''), locale);
|
||||
let isGDate = hasGR &&
|
||||
isValidDate(sA.replace(re_g, ''), locale);
|
||||
let isGEDate = hasGE &&
|
||||
isValidDate(sA.replace(re_ge, ''), locale);
|
||||
let isDFDate = hasDF &&
|
||||
isValidDate(sA.replace(re_d, ''), locale);
|
||||
let isEQDate = hasEQ &&
|
||||
isValidDate(sA.replace(re_eq, ''), locale);
|
||||
|
||||
dte1 = parseDate(cellData, locale);
|
||||
|
||||
let dte1, dte2;
|
||||
//dates
|
||||
if (isValidDate(cellData, dtType)) {
|
||||
dte1 = formatDate(cellData, dtType);
|
||||
// lower date
|
||||
if (isLDate) {
|
||||
dte2 = formatDate(sA.replace(re_l, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_l, ''), locale);
|
||||
occurence = dte1 < dte2;
|
||||
}
|
||||
// lower equal date
|
||||
else if (isLEDate) {
|
||||
dte2 = formatDate(sA.replace(re_le, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_le, ''), locale);
|
||||
occurence = dte1 <= dte2;
|
||||
}
|
||||
// greater equal date
|
||||
else if (isGEDate) {
|
||||
dte2 = formatDate(sA.replace(re_ge, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_ge, ''), locale);
|
||||
occurence = dte1 >= dte2;
|
||||
}
|
||||
// greater date
|
||||
else if (isGDate) {
|
||||
dte2 = formatDate(sA.replace(re_g, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_g, ''), locale);
|
||||
occurence = dte1 > dte2;
|
||||
}
|
||||
// different date
|
||||
else if (isDFDate) {
|
||||
dte2 = formatDate(sA.replace(re_d, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_d, ''), locale);
|
||||
occurence = dte1.toString() !== dte2.toString();
|
||||
}
|
||||
// equal date
|
||||
else if (isEQDate) {
|
||||
dte2 = formatDate(sA.replace(re_eq, ''), dtType);
|
||||
dte2 = parseDate(sA.replace(re_eq, ''), locale);
|
||||
occurence = dte1.toString() === dte2.toString();
|
||||
}
|
||||
// searched keyword with * operator doesn't have to be a date
|
||||
|
@ -1844,8 +1860,8 @@ export class TableFilter {
|
|||
occurence = contains(sA.replace(re_lk, ''), cellData,
|
||||
false, this.caseSensitive);
|
||||
}
|
||||
else if (isValidDate(sA, dtType)) {
|
||||
dte2 = formatDate(sA, dtType);
|
||||
else if (isValidDate(sA)) {
|
||||
dte2 = parseDate(sA, locale);
|
||||
occurence = dte1.toString() === dte2.toString();
|
||||
}
|
||||
//empty
|
||||
|
@ -1856,48 +1872,51 @@ export class TableFilter {
|
|||
else if (hasNM) {
|
||||
occurence = !isEmptyString(cellData);
|
||||
} else {
|
||||
occurence = contains(sA, cellData, this.isExactMatch(j),
|
||||
this.caseSensitive);
|
||||
occurence = contains(sA, cellData,
|
||||
this.isExactMatch(colIdx), this.caseSensitive);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
//first numbers need to be formated
|
||||
if (this.hasColNbFormat && this.colNbFormat[j]) {
|
||||
numCellData = removeNbFormat(cellData, this.colNbFormat[j]);
|
||||
nbFormat = this.colNbFormat[j];
|
||||
} else {
|
||||
if (this.thousandsSeparator === ',' &&
|
||||
this.decimalSeparator === '.') {
|
||||
numCellData = removeNbFormat(cellData, 'us');
|
||||
nbFormat = 'us';
|
||||
} else {
|
||||
numCellData = removeNbFormat(cellData, 'eu');
|
||||
nbFormat = 'eu';
|
||||
if (this.hasType(colIdx, [FORMATTED_NUMBER])) {
|
||||
let colType = this.colTypes[colIdx];
|
||||
if (colType.hasOwnProperty('decimal')) {
|
||||
decimal = colType.decimal;
|
||||
}
|
||||
}
|
||||
// Convert to number anyways to auto-resolve type in case not
|
||||
// defined by configuration
|
||||
numData = Number(cellData) || parseNb(cellData, decimal);
|
||||
|
||||
// first checks if there is any operator (<,>,<=,>=,!,*,=,{,},
|
||||
// rgx:)
|
||||
// lower equal
|
||||
if (hasLE) {
|
||||
occurence = numCellData <= removeNbFormat(
|
||||
sA.replace(re_le, ''), nbFormat);
|
||||
occurence = numData <= parseNb(
|
||||
sA.replace(re_le, ''),
|
||||
decimal
|
||||
);
|
||||
}
|
||||
//greater equal
|
||||
else if (hasGE) {
|
||||
occurence = numCellData >= removeNbFormat(
|
||||
sA.replace(re_ge, ''), nbFormat);
|
||||
occurence = numData >= parseNb(
|
||||
sA.replace(re_ge, ''),
|
||||
decimal
|
||||
);
|
||||
}
|
||||
//lower
|
||||
else if (hasLO) {
|
||||
occurence = numCellData < removeNbFormat(
|
||||
sA.replace(re_l, ''), nbFormat);
|
||||
occurence = numData < parseNb(
|
||||
sA.replace(re_l, ''),
|
||||
decimal
|
||||
);
|
||||
}
|
||||
//greater
|
||||
else if (hasGR) {
|
||||
occurence = numCellData > removeNbFormat(
|
||||
sA.replace(re_g, ''), nbFormat);
|
||||
occurence = numData > parseNb(
|
||||
sA.replace(re_g, ''),
|
||||
decimal
|
||||
);
|
||||
}
|
||||
//different
|
||||
else if (hasDF) {
|
||||
|
@ -1950,19 +1969,20 @@ 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 (numData &&
|
||||
this.hasType(colIdx, [NUMBER, FORMATTED_NUMBER]) &&
|
||||
!this.singleSearchFlt) {
|
||||
// parseNb 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;
|
||||
occurence = numCellData === sA ||
|
||||
contains(sA.toString(), numCellData.toString(),
|
||||
this.isExactMatch(j), this.caseSensitive);
|
||||
// string. TODO: handle this in parseNb
|
||||
sA = parseNb(sA, decimal) || sA;
|
||||
occurence = numData === sA ||
|
||||
contains(sA.toString(), numData.toString(),
|
||||
this.isExactMatch(colIdx), this.caseSensitive);
|
||||
} else {
|
||||
// Finally test search term is contained in cell data
|
||||
occurence = contains(sA, cellData, this.isExactMatch(j),
|
||||
this.caseSensitive);
|
||||
occurence = contains(sA, cellData,
|
||||
this.isExactMatch(colIdx), this.caseSensitive);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2111,11 +2131,17 @@ 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 decimal = this.decimalSeparator;
|
||||
if (this.hasType(colIndex, [FORMATTED_NUMBER])) {
|
||||
let colType = this.colTypes[colIndex];
|
||||
if (colType.hasOwnProperty('decimal')) {
|
||||
decimal = colType.decimal;
|
||||
}
|
||||
}
|
||||
let data = num ?
|
||||
Number(cellData) || parseNb(cellData, decimal) :
|
||||
cellData;
|
||||
colValues.push(data);
|
||||
}
|
||||
}
|
||||
|
@ -2823,6 +2849,23 @@ 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 = []) {
|
||||
if (!this.hasColTypes) {
|
||||
return false;
|
||||
}
|
||||
let colType = this.colTypes[colIndex];
|
||||
if (isObj(colType)) {
|
||||
colType = colType.type;
|
||||
}
|
||||
return types.indexOf(colType) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header DOM element for a given column index
|
||||
* @param {Number} colIndex Column index
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
<script data-config>
|
||||
var tfConfig = {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_types: [
|
||||
'number', 'string', 'string',
|
||||
'formatted-number', 'formatted-number', 'string'
|
||||
],
|
||||
paging: true,
|
||||
state: {
|
||||
types: ['cookie'],
|
||||
|
@ -49,11 +53,7 @@ var tfConfig = {
|
|||
text: 'Columns: ',
|
||||
enable_tick_all: true
|
||||
}, {
|
||||
name: 'sort',
|
||||
types: [
|
||||
'number', 'string', 'string',
|
||||
'US', 'none', 'string'
|
||||
]
|
||||
name: 'sort'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
@ -8,16 +8,17 @@
|
|||
<h1>{NAME} v{VERSION}</h1>
|
||||
<h2>Data types demo</h2>
|
||||
|
||||
<p>This example features 3 date types and 2 numeric formatting for the currency
|
||||
columns:</p>
|
||||
<p>
|
||||
This example shows how to define column types with the
|
||||
<code>col_types</code> option and specifically numeric formats with:
|
||||
</p>
|
||||
<ul>
|
||||
<li>"." thousands separator and "," decimal separator for €</li>
|
||||
<li>"," thousands separator and "." decimal separator for US$</li>
|
||||
<li>"." thousands separator and "," decimal separator for € column</li>
|
||||
<li>"," thousands separator and "." decimal separator for US$ column</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
|
||||
types.
|
||||
along with date types with <code>locale</code> and <code>format</code> specified on
|
||||
a column basis.
|
||||
</p>
|
||||
|
||||
<!-- @import partials/pre.html -->
|
||||
|
@ -75,29 +76,29 @@ var tfConfig = {
|
|||
btn_reset: true,
|
||||
loader: true,
|
||||
status_bar: true,
|
||||
col_number_format: [
|
||||
null, null, null,
|
||||
'EU', 'US', null,
|
||||
null, null, null,
|
||||
'IpAddress'
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
null, null, null,
|
||||
'dmy', 'mdy', 'ddmmmyyyy',
|
||||
null
|
||||
col_types: [
|
||||
'string',
|
||||
'string',
|
||||
'string',
|
||||
{ type: 'formatted-number', decimal: ',', thousands: '.' },
|
||||
'formatted-number', // defaults to '.' for decimal and ',' for thousands
|
||||
'string',
|
||||
{ type: 'date', locale: 'fr' },
|
||||
{ type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' },
|
||||
{ type: 'date', locale: 'en', format: ['{dd}-{months}-{yyyy|yy}'] },
|
||||
'ipaddress'
|
||||
],
|
||||
rows_always_visible: [totRowIndex],
|
||||
on_filters_loaded: function(o){
|
||||
o.setFilterValue(3, '>1.000');
|
||||
o.setFilterValue(4, '<2,500');
|
||||
o.setFilterValue(6, '>23-01-95');
|
||||
o.filter();
|
||||
on_filters_loaded: function(tf){
|
||||
tf.setFilterValue(3, '>1.000');
|
||||
tf.setFilterValue(4, '<2,500');
|
||||
tf.setFilterValue(6, '>23-01-95');
|
||||
tf.setFilterValue(8, '<2000');
|
||||
tf.filter();
|
||||
},
|
||||
extensions:[
|
||||
{ name: 'sort' },
|
||||
{
|
||||
name: 'sort'
|
||||
},{
|
||||
name: 'colOps',
|
||||
id: ['sum1', 'sum2'],
|
||||
col: [3, 4],
|
||||
|
@ -116,8 +117,11 @@ tf.init();
|
|||
|
||||
</script>
|
||||
|
||||
<p>Below an example of ISO date support (YMD). Use <code>default_date_type</code>
|
||||
to set a date type for a whole table ('DMY','MDY','YMD').</p>
|
||||
<p>
|
||||
Below an example of ISO date support ({yyyy|yy}/{MM}/{dd}).
|
||||
Use <code>locale</code> to set a locale globally
|
||||
(defaults to 'en').
|
||||
</p>
|
||||
|
||||
<!-- @import partials/dummy-table.html -->
|
||||
<script data-config>
|
||||
|
@ -130,12 +134,17 @@ var tf2Config = {
|
|||
btn_reset: true,
|
||||
loader: true,
|
||||
status_bar: true,
|
||||
default_date_type: 'YMD',
|
||||
on_filters_loaded: function(o){
|
||||
o.setFilterValue(5, '>95-05-18');
|
||||
o.filter();
|
||||
locale: 'en-US',
|
||||
col_types: [
|
||||
'string', 'number', 'string',
|
||||
'number', 'string', 'date'
|
||||
],
|
||||
on_filters_loaded: function(tf){
|
||||
tf.setFilterValue(5, '>95-05-18');
|
||||
tf.filter();
|
||||
}
|
||||
};
|
||||
|
||||
var tf2 = new TableFilter('demo', tf2Config);
|
||||
tf2.init();
|
||||
</script>
|
||||
|
|
|
@ -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,13 +22,9 @@ var tfConfig = {
|
|||
base_path: '../dist/tablefilter/',
|
||||
filters_row_index: 2,
|
||||
headers_row_index: 1,
|
||||
col_number_format: [
|
||||
null, null, null,
|
||||
'US', null, null, null
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
null, null, null, 'mdy'
|
||||
col_types: [
|
||||
'string', 'string', 'string',
|
||||
'number', 'string', 'string', 'date'
|
||||
],
|
||||
rows_counter: true,
|
||||
rows_counter_text: 'Books: ',
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
'120px', '120px', '100px',
|
||||
'100px', '100px', '100px'
|
||||
],
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
],
|
||||
extensions:[{
|
||||
name: 'sort',
|
||||
types: [
|
||||
'string', 'string', 'number',
|
||||
'number', 'number', 'number',
|
||||
'number', 'number', 'number'
|
||||
]
|
||||
name: 'sort'
|
||||
}]
|
||||
};
|
||||
|
||||
|
|
|
@ -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,13 +30,9 @@ var tfConfig = {
|
|||
filters_row_index: 2,
|
||||
headers_row_index: 1,
|
||||
sort: true,
|
||||
col_number_format: [
|
||||
null, null, 'US',
|
||||
null, null, null
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
null, null, 'mdy'
|
||||
col_types: [
|
||||
'string', 'string', 'number',
|
||||
'string', 'string', 'date'
|
||||
],
|
||||
rows_counter: true,
|
||||
rows_counter_text: 'Books: ',
|
||||
|
|
|
@ -2,17 +2,14 @@
|
|||
// TODO: add sort to test it with different column types
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_number_format: [
|
||||
null, null, null,
|
||||
'EU', 'US', null,
|
||||
col_types: [
|
||||
null, null, null,
|
||||
{ type: 'formatted-number', decimal: ',', thousands: ','},
|
||||
'formatted-number', null,
|
||||
{ type: 'date', locale: 'fr', },
|
||||
{ type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' },
|
||||
{ type: 'date', locale: 'en', format: ['{dd}-{months}-{yyyy|yy}'] },
|
||||
'IpAddress'
|
||||
],
|
||||
col_date_type: [
|
||||
null, null, null,
|
||||
null, null, null,
|
||||
'dmy', 'mdy', 'ddmmmyyyy',
|
||||
null
|
||||
]
|
||||
});
|
||||
tf.init();
|
||||
|
@ -21,8 +18,17 @@
|
|||
module('Sanity checks');
|
||||
test('Data types', function() {
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
deepEqual(tf.hasColNbFormat, true, 'Has number column types');
|
||||
deepEqual(tf.hasColDateType, true, 'Has date column tyoes');
|
||||
deepEqual(
|
||||
tf.hasType(3, ['formatted-number']) &&
|
||||
tf.hasType(4, ['formatted-number']),
|
||||
true, 'Has number column types'
|
||||
);
|
||||
deepEqual(
|
||||
tf.hasType(6, ['date']) &&
|
||||
tf.hasType(7, ['date']) &&
|
||||
tf.hasType(8, ['date']),
|
||||
true, 'Has date column types'
|
||||
);
|
||||
});
|
||||
|
||||
module('Data types filtering');
|
||||
|
@ -86,7 +92,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 +104,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 +116,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 +129,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 +167,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 +179,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();
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
// issue 162 - https://github.com/koalyptus/TableFilter/issues/162
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_date_type: ['DMY']
|
||||
locale: 'en-GB',
|
||||
col_types: ['date', 'string']
|
||||
});
|
||||
tf.init();
|
||||
|
||||
|
@ -17,7 +18,7 @@
|
|||
// assert
|
||||
deepEqual(tf.getValidRows().length, 0, 'Expected filtered rows');
|
||||
});
|
||||
test('Can filter DMY date type', function(){
|
||||
test('Can filter dd.MM.yyyy date type', function(){
|
||||
// setup
|
||||
tf.clearFilters();
|
||||
// act
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
col_date_type: [
|
||||
null, null, 'ddmmmyyyy',
|
||||
null, null, null
|
||||
],
|
||||
col_number_format: [
|
||||
null, null, null,
|
||||
null, null, 'US'
|
||||
col_types: [
|
||||
null,
|
||||
{ type: 'date', format: ['{dd}.{MM}.{yyyy|yy}'] },
|
||||
{ type: 'date', format: ['{dd}.{months}.{yyyy}'] },
|
||||
null,
|
||||
null,
|
||||
'formatted-number'
|
||||
]
|
||||
});
|
||||
tf.init();
|
||||
|
|
Loading…
Reference in a new issue