1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-03 23:23:17 +02:00

Re-refactored number type, continued

This commit is contained in:
Max Guglielmi 2016-09-19 20:35:34 +10:00
parent 7ecb53a701
commit bfe7293619
9 changed files with 62 additions and 180 deletions

View file

@ -1949,7 +1949,7 @@ return /******/ (function(modules) { // webpackBootstrap
var searchArgs = this.getFiltersValue(); var searchArgs = this.getFiltersValue();
var numData = void 0; var numData = void 0;
var nbFormat = this.decimalSeparator; var decimal = this.decimalSeparator;
var re_le = new RegExp(this.leOperator), var re_le = new RegExp(this.leOperator),
re_ge = new RegExp(this.geOperator), re_ge = new RegExp(this.geOperator),
re_l = new RegExp(this.lwOperator), re_l = new RegExp(this.lwOperator),
@ -2024,6 +2024,7 @@ return /******/ (function(modules) { // webpackBootstrap
var parseDate = dateType.parse.bind(dateType); var parseDate = dateType.parse.bind(dateType);
var locale = dateType.getOptions(colIdx).locale || this.locale; var locale = dateType.getOptions(colIdx).locale || this.locale;
// Search arg dates tests
var isLDate = hasLO && isValidDate(sA.replace(re_l, ''), locale); var isLDate = hasLO && isValidDate(sA.replace(re_l, ''), locale);
var isLEDate = hasLE && isValidDate(sA.replace(re_le, ''), locale); var isLEDate = hasLE && isValidDate(sA.replace(re_le, ''), locale);
var isGDate = hasGR && isValidDate(sA.replace(re_g, ''), locale); var isGDate = hasGR && isValidDate(sA.replace(re_g, ''), locale);
@ -2090,55 +2091,36 @@ return /******/ (function(modules) { // webpackBootstrap
occurence = (0, _string.contains)(sA, cellData, this.isExactMatch(colIdx), this.caseSensitive); occurence = (0, _string.contains)(sA, cellData, this.isExactMatch(colIdx), this.caseSensitive);
} }
} else { } else {
//first numbers need to be unformatted if (this.hasType(colIdx, [_const.FORMATTED_NUMBER])) {
// if (this.hasType(colIdx, [NUMBER])) {
// numData = Number(cellData);
// }
// else if (this.hasType(colIdx,
// [FORMATTED_NUMBER, FORMATTED_NUMBER_EU])) {
// numData =unformatNb(cellData, this.colTypes[colIdx]);
// nbFormat = this.colTypes[colIdx];
// } else {
// if (this.thousandsSeparator === ',' &&
// this.decimalSeparator === '.') {
// nbFormat = FORMATTED_NUMBER;
// } else {
// nbFormat = FORMATTED_NUMBER_EU;
// }
// numData = unformatNb(cellData, nbFormat);
// }
if (this.hasType(colIdx, [_const.NUMBER
/*, FORMATTED_NUMBER, FORMATTED_NUMBER_EU*/])) {
var colType = this.colTypes[colIdx]; var colType = this.colTypes[colIdx];
if (colType.hasOwnProperty('decimal')) { if (colType.hasOwnProperty('decimal')) {
nbFormat = colType.decimal; decimal = colType.decimal;
} }
// numData = Number(cellData) ||parseNb(cellData, nbFormat); // numData = Number(cellData) ||parseNb(cellData, decimal);
} }
// else { // else {
// numData = Number(cellData) || // numData = Number(cellData) ||
// parseNb(cellData, tf.decimalSeparator); // parseNb(cellData, tf.decimalSeparator);
// } // }
numData = Number(cellData) || (0, _number.parse)(cellData, nbFormat); numData = Number(cellData) || (0, _number.parse)(cellData, decimal);
// first checks if there is any operator (<,>,<=,>=,!,*,=,{,}, // first checks if there is any operator (<,>,<=,>=,!,*,=,{,},
// rgx:) // rgx:)
// lower equal // lower equal
if (hasLE) { if (hasLE) {
occurence = numData <= (0, _number.parse)(sA.replace(re_le, ''), nbFormat); occurence = numData <= (0, _number.parse)(sA.replace(re_le, ''), decimal);
} }
//greater equal //greater equal
else if (hasGE) { else if (hasGE) {
occurence = numData >= (0, _number.parse)(sA.replace(re_ge, ''), nbFormat); occurence = numData >= (0, _number.parse)(sA.replace(re_ge, ''), decimal);
} }
//lower //lower
else if (hasLO) { else if (hasLO) {
occurence = numData < (0, _number.parse)(sA.replace(re_l, ''), nbFormat); occurence = numData < (0, _number.parse)(sA.replace(re_l, ''), decimal);
} }
//greater //greater
else if (hasGR) { else if (hasGR) {
occurence = numData > (0, _number.parse)(sA.replace(re_g, ''), nbFormat); occurence = numData > (0, _number.parse)(sA.replace(re_g, ''), decimal);
} }
//different //different
else if (hasDF) { else if (hasDF) {
@ -2183,11 +2165,11 @@ return /******/ (function(modules) { // webpackBootstrap
} else { } else {
// If numeric type data, perform a strict equality test and // If numeric type data, perform a strict equality test and
// fallback to unformatted number string comparison // fallback to unformatted number string comparison
if (numData && this.hasType(colIdx, [_const.NUMBER]) && !this.singleSearchFlt) { if (numData && this.hasType(colIdx, [_const.NUMBER, _const.FORMATTED_NUMBER]) && !this.singleSearchFlt) {
// parseNb can return 0 for strings which are not // parseNb can return 0 for strings which are not
// formatted numbers, in that case return the original // formatted numbers, in that case return the original
// string. TODO: handle this in parseNb // string. TODO: handle this in parseNb
sA = (0, _number.parse)(sA, nbFormat) || sA; sA = (0, _number.parse)(sA, decimal) || sA;
occurence = numData === sA || (0, _string.contains)(sA.toString(), numData.toString(), this.isExactMatch(colIdx), this.caseSensitive); occurence = numData === sA || (0, _string.contains)(sA.toString(), numData.toString(), this.isExactMatch(colIdx), this.caseSensitive);
} else { } else {
// Finally test search term is contained in cell data // Finally test search term is contained in cell data
@ -2346,17 +2328,17 @@ return /******/ (function(modules) { // webpackBootstrap
continue; continue;
} }
var cellData = this.getCellData(cell[j]); var cellData = this.getCellData(cell[j]);
// let nbFormat = this.hasType(colIndex, // let decimal = this.hasType(colIndex,
// [FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) ? // [FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) ?
// this.colTypes[colIndex] : undefined; // this.colTypes[colIndex] : undefined;
var decimal = this.decimalSeparator; var decimal = this.decimalSeparator;
if (this.hasType(colIndex, [_const.NUMBER])) { if (this.hasType(colIndex, [_const.FORMATTED_NUMBER])) {
var colType = this.colTypes[colIndex]; var colType = this.colTypes[colIndex];
if (colType.hasOwnProperty('decimal')) { if (colType.hasOwnProperty('decimal')) {
decimal = colType.decimal; decimal = colType.decimal;
} }
} }
var data = num ? (0, _number.parse)(cellData, decimal) : cellData; var data = num ? Number(cellData) || (0, _number.parse)(cellData, decimal) : cellData;
colValues.push(data); colValues.push(data);
} }
} }
@ -4688,12 +4670,6 @@ return /******/ (function(modules) { // webpackBootstrap
*/ */
var FORMATTED_NUMBER = exports.FORMATTED_NUMBER = 'formatted-number'; var FORMATTED_NUMBER = exports.FORMATTED_NUMBER = 'formatted-number';
/**
* Formatted number
* @type {String}
*/
var FORMATTED_NUMBER_EU = exports.FORMATTED_NUMBER_EU = 'formatted-number-eu';
/** /**
* Date * Date
* @type {String} * @type {String}
@ -10220,8 +10196,6 @@ return /******/ (function(modules) { // webpackBootstrap
// Global locale // Global locale
this.datetime.setLocale(this.locale); this.datetime.setLocale(this.locale);
// let locale = this.datetime.getLocale(this.locale);
// Add formats from column types configuration if any // Add formats from column types configuration if any
this.addConfigFormats(this.tf.colTypes); this.addConfigFormats(this.tf.colTypes);
// locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{dd}/{MM}/{yyyy}');
@ -10256,7 +10230,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _this = this; var _this = this;
var types = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; var types = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
console.log(types);
types.forEach(function (type, idx) { types.forEach(function (type, idx) {
var options = _this.getOptions(idx, types); var options = _this.getOptions(idx, types);
if (options.hasOwnProperty('format')) { if (options.hasOwnProperty('format')) {

View file

@ -2841,12 +2841,13 @@ webpackJsonp([1],{
if ((0, _types.isObj)(colType)) { if ((0, _types.isObj)(colType)) {
if (colType.type === _const.DATE) { if (colType.type === _const.DATE) {
colType = this._addDateType(i, sortTypes); colType = this._addDateType(i, sortTypes);
} else if (colType.type === _const.NUMBER) { } else if (colType.type === _const.FORMATTED_NUMBER) {
var decimal = colType.decimal || tf.decimalSeparator; var decimal = colType.decimal || tf.decimalSeparator;
colType = this._addNumberType(i, decimal); colType = this._addNumberType(i, decimal);
} }
} else { } else {
colType = colType.toLowerCase(); colType = colType.toLowerCase();
// TODO: normalise 'none' vs 'None'
if (colType === _const.NONE) { if (colType === _const.NONE) {
colType = 'None'; colType = 'None';
} }
@ -2854,30 +2855,6 @@ webpackJsonp([1],{
} else { } else {
colType = _const.STRING; colType = _const.STRING;
} }
// if (sortTypes[i]) {
// colType = sortTypes[i];
// if (isObj(colType)) {
// if (colType.type === DATE) {
// colType = this._addDateType(i, sortTypes);
// }
// else if (colType.type === NUMBER) {
// }
// }
// colType = colType.toLowerCase();
// if (colType === NONE) {
// colType = 'None';
// }
// } else { // resolve column types
// if (tf.hasType(i, [NUMBER/*, FORMATTED_NUMBER,
// FORMATTED_NUMBER_EU, IP_ADDRESS*/])) {
// colType = tf.colTypes[i].toLowerCase();
// } else if (tf.hasType(i, [DATE])) {
// colType = this._addDateType(i);
// } else {
// colType = STRING;
// }
// }
_sortTypes.push(colType); _sortTypes.push(colType);
} }
@ -2887,10 +2864,8 @@ webpackJsonp([1],{
this.addSortType(_const.NUMBER, Number); this.addSortType(_const.NUMBER, Number);
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase); this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
this.addSortType(_const.STRING); this.addSortType(_const.STRING);
// this.addSortType(FORMATTED_NUMBER, usNumberConverter);
// this.addSortType(FORMATTED_NUMBER_EU, euNumberConverter);
this.addSortType(_const.IP_ADDRESS, ipAddress, sortIP); this.addSortType(_const.IP_ADDRESS, ipAddress, sortIP);
console.log(_sortTypes);
this.stt = new SortableTable(tf.tbl, _sortTypes); this.stt = new SortableTable(tf.tbl, _sortTypes);
/*** external table headers adapter ***/ /*** external table headers adapter ***/
@ -2932,7 +2907,7 @@ webpackJsonp([1],{
}; };
AdapterSortableTable.prototype._addNumberType = function _addNumberType(colIndex, decimal) { AdapterSortableTable.prototype._addNumberType = function _addNumberType(colIndex, decimal) {
var colType = _const.NUMBER + '-format' + (decimal === '.' ? '' : '-custom'); var colType = '' + _const.FORMATTED_NUMBER + (decimal === '.' ? '' : '-custom');
this.addSortType(colType, function (value) { this.addSortType(colType, function (value) {
return (0, _number.parse)(value, decimal); return (0, _number.parse)(value, decimal);
@ -2975,12 +2950,7 @@ webpackJsonp([1],{
}(_feature.Feature); }(_feature.Feature);
//Converters //Converters
// function usNumberConverter(s) {
// return parseNb(s, FORMATTED_NUMBER);
// }
// function euNumberConverter(s) {
// return parseNb(s, FORMATTED_NUMBER_EU);
// }
exports.default = AdapterSortableTable; exports.default = AdapterSortableTable;
function ipAddress(value) { function ipAddress(value) {

View file

@ -51,7 +51,7 @@
"string-replace-webpack-plugin": "^0.0.3", "string-replace-webpack-plugin": "^0.0.3",
"sugar-date": "2.0.0", "sugar-date": "2.0.0",
"webpack": "^1.13.2", "webpack": "^1.13.2",
"webpack-dev-server": "^1.15.1" "webpack-dev-server": "^1.16.1"
}, },
"dependencies": {}, "dependencies": {},
"bugs": { "bugs": {

View file

@ -95,12 +95,6 @@ export const NUMBER = 'number';
*/ */
export const FORMATTED_NUMBER = 'formatted-number'; export const FORMATTED_NUMBER = 'formatted-number';
/**
* Formatted number
* @type {String}
*/
export const FORMATTED_NUMBER_EU = 'formatted-number-eu';
/** /**
* Date * Date
* @type {String} * @type {String}

View file

@ -4,8 +4,8 @@ import {createElm, elm, getText, tag} from '../../dom';
import {addEvt} from '../../event'; import {addEvt} from '../../event';
import {parse as parseNb} from '../../number'; import {parse as parseNb} from '../../number';
import { import {
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, /*FORMATTED_NUMBER, NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
FORMATTED_NUMBER_EU,*/ IP_ADDRESS IP_ADDRESS
} from '../../const'; } from '../../const';
/** /**
@ -407,12 +407,13 @@ export default class AdapterSortableTable extends Feature {
if (colType.type === DATE) { if (colType.type === DATE) {
colType = this._addDateType(i, sortTypes); colType = this._addDateType(i, sortTypes);
} }
else if (colType.type === NUMBER) { else if (colType.type === FORMATTED_NUMBER) {
let decimal = colType.decimal || tf.decimalSeparator; let decimal = colType.decimal || tf.decimalSeparator;
colType = this._addNumberType(i, decimal); colType = this._addNumberType(i, decimal);
} }
} else { } else {
colType = colType.toLowerCase(); colType = colType.toLowerCase();
// TODO: normalise 'none' vs 'None'
if (colType === NONE) { if (colType === NONE) {
colType = 'None'; colType = 'None';
} }
@ -420,30 +421,6 @@ export default class AdapterSortableTable extends Feature {
} else { } else {
colType = STRING; colType = STRING;
} }
// if (sortTypes[i]) {
// colType = sortTypes[i];
// if (isObj(colType)) {
// if (colType.type === DATE) {
// colType = this._addDateType(i, sortTypes);
// }
// else if (colType.type === NUMBER) {
// }
// }
// colType = colType.toLowerCase();
// if (colType === NONE) {
// colType = 'None';
// }
// } else { // resolve column types
// if (tf.hasType(i, [NUMBER/*, FORMATTED_NUMBER,
// FORMATTED_NUMBER_EU, IP_ADDRESS*/])) {
// colType = tf.colTypes[i].toLowerCase();
// } else if (tf.hasType(i, [DATE])) {
// colType = this._addDateType(i);
// } else {
// colType = STRING;
// }
// }
_sortTypes.push(colType); _sortTypes.push(colType);
} }
@ -453,10 +430,8 @@ export default class AdapterSortableTable extends Feature {
this.addSortType(NUMBER, Number); this.addSortType(NUMBER, Number);
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase); this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
this.addSortType(STRING); this.addSortType(STRING);
// this.addSortType(FORMATTED_NUMBER, usNumberConverter);
// this.addSortType(FORMATTED_NUMBER_EU, euNumberConverter);
this.addSortType(IP_ADDRESS, ipAddress, sortIP); this.addSortType(IP_ADDRESS, ipAddress, sortIP);
console.log(_sortTypes);
this.stt = new SortableTable(tf.tbl, _sortTypes); this.stt = new SortableTable(tf.tbl, _sortTypes);
/*** external table headers adapter ***/ /*** external table headers adapter ***/
@ -496,7 +471,7 @@ export default class AdapterSortableTable extends Feature {
} }
_addNumberType(colIndex, decimal) { _addNumberType(colIndex, decimal) {
let colType = `${NUMBER}-format${decimal === '.' ? '' : '-custom'}`; let colType = `${FORMATTED_NUMBER}${decimal === '.' ? '' : '-custom'}`;
this.addSortType(colType, (value) => { this.addSortType(colType, (value) => {
return parseNb(value, decimal); return parseNb(value, decimal);
@ -533,13 +508,6 @@ export default class AdapterSortableTable extends Feature {
} }
//Converters //Converters
// function usNumberConverter(s) {
// return parseNb(s, FORMATTED_NUMBER);
// }
// function euNumberConverter(s) {
// return parseNb(s, FORMATTED_NUMBER_EU);
// }
function ipAddress(value) { function ipAddress(value) {
let vals = value.split('.'); let vals = value.split('.');
for (let x in vals) { for (let x in vals) {

View file

@ -19,8 +19,6 @@ export class DateType {
// Global locale // Global locale
this.datetime.setLocale(this.locale); this.datetime.setLocale(this.locale);
// let locale = this.datetime.getLocale(this.locale);
// Add formats from column types configuration if any // Add formats from column types configuration if any
this.addConfigFormats(this.tf.colTypes); this.addConfigFormats(this.tf.colTypes);
// locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{dd}/{MM}/{yyyy}');
@ -51,7 +49,7 @@ export class DateType {
return isObj(colType) ? colType : {}; return isObj(colType) ? colType : {};
} }
addConfigFormats(types=[]) {console.log(types); addConfigFormats(types=[]) {
types.forEach((type, idx) => { types.forEach((type, idx) => {
let options = this.getOptions(idx, types); let options = this.getOptions(idx, types);
if (options.hasOwnProperty('format')) { if (options.hasOwnProperty('format')) {

View file

@ -31,8 +31,7 @@ import {DateType} from './modules/dateType';
import { import {
INPUT, SELECT, MULTIPLE, CHECKLIST, NONE, INPUT, SELECT, MULTIPLE, CHECKLIST, NONE,
ENTER_KEY, TAB_KEY, ESC_KEY, UP_ARROW_KEY, DOWN_ARROW_KEY, ENTER_KEY, TAB_KEY, ESC_KEY, UP_ARROW_KEY, DOWN_ARROW_KEY,
CELL_TAG, AUTO_FILTER_DELAY, NUMBER, DATE/*, FORMATTED_NUMBER, CELL_TAG, AUTO_FILTER_DELAY, NUMBER, DATE, FORMATTED_NUMBER
FORMATTED_NUMBER_EU*/
} from './const'; } from './const';
let doc = root.document; let doc = root.document;
@ -1753,7 +1752,7 @@ export class TableFilter {
let searchArgs = this.getFiltersValue(); let searchArgs = this.getFiltersValue();
let numData; let numData;
let nbFormat = this.decimalSeparator; let decimal = this.decimalSeparator;
let re_le = new RegExp(this.leOperator), let re_le = new RegExp(this.leOperator),
re_ge = new RegExp(this.geOperator), re_ge = new RegExp(this.geOperator),
re_l = new RegExp(this.lwOperator), re_l = new RegExp(this.lwOperator),
@ -1826,6 +1825,7 @@ export class TableFilter {
let parseDate = dateType.parse.bind(dateType); let parseDate = dateType.parse.bind(dateType);
let locale = dateType.getOptions(colIdx).locale || this.locale; let locale = dateType.getOptions(colIdx).locale || this.locale;
// Search arg dates tests
let isLDate = hasLO && let isLDate = hasLO &&
isValidDate(sA.replace(re_l, ''), locale); isValidDate(sA.replace(re_l, ''), locale);
let isLEDate = hasLE && let isLEDate = hasLE &&
@ -1902,36 +1902,18 @@ export class TableFilter {
} }
else { else {
//first numbers need to be unformatted if (this.hasType(colIdx, [FORMATTED_NUMBER])) {
// if (this.hasType(colIdx, [NUMBER])) {
// numData = Number(cellData);
// }
// else if (this.hasType(colIdx,
// [FORMATTED_NUMBER, FORMATTED_NUMBER_EU])) {
// numData =unformatNb(cellData, this.colTypes[colIdx]);
// nbFormat = this.colTypes[colIdx];
// } else {
// if (this.thousandsSeparator === ',' &&
// this.decimalSeparator === '.') {
// nbFormat = FORMATTED_NUMBER;
// } else {
// nbFormat = FORMATTED_NUMBER_EU;
// }
// numData = unformatNb(cellData, nbFormat);
// }
if (this.hasType(colIdx, [NUMBER])) {
let colType = this.colTypes[colIdx]; let colType = this.colTypes[colIdx];
if (colType.hasOwnProperty('decimal')) { if (colType.hasOwnProperty('decimal')) {
nbFormat = colType.decimal; decimal = colType.decimal;
} }
// numData = Number(cellData) ||parseNb(cellData, nbFormat); // numData = Number(cellData) ||parseNb(cellData, decimal);
} }
// else { // else {
// numData = Number(cellData) || // numData = Number(cellData) ||
// parseNb(cellData, tf.decimalSeparator); // parseNb(cellData, tf.decimalSeparator);
// } // }
numData = Number(cellData) || parseNb(cellData, nbFormat); numData = Number(cellData) || parseNb(cellData, decimal);
// first checks if there is any operator (<,>,<=,>=,!,*,=,{,}, // first checks if there is any operator (<,>,<=,>=,!,*,=,{,},
// rgx:) // rgx:)
@ -1939,28 +1921,28 @@ export class TableFilter {
if (hasLE) { if (hasLE) {
occurence = numData <= parseNb( occurence = numData <= parseNb(
sA.replace(re_le, ''), sA.replace(re_le, ''),
nbFormat decimal
); );
} }
//greater equal //greater equal
else if (hasGE) { else if (hasGE) {
occurence = numData >= parseNb( occurence = numData >= parseNb(
sA.replace(re_ge, ''), sA.replace(re_ge, ''),
nbFormat decimal
); );
} }
//lower //lower
else if (hasLO) { else if (hasLO) {
occurence = numData < parseNb( occurence = numData < parseNb(
sA.replace(re_l, ''), sA.replace(re_l, ''),
nbFormat decimal
); );
} }
//greater //greater
else if (hasGR) { else if (hasGR) {
occurence = numData > parseNb( occurence = numData > parseNb(
sA.replace(re_g, ''), sA.replace(re_g, ''),
nbFormat decimal
); );
} }
//different //different
@ -2015,14 +1997,12 @@ export class TableFilter {
// If numeric type data, perform a strict equality test and // If numeric type data, perform a strict equality test and
// fallback to unformatted number string comparison // fallback to unformatted number string comparison
if (numData && if (numData &&
this.hasType(colIdx, this.hasType(colIdx, [NUMBER, FORMATTED_NUMBER]) &&
[NUMBER
/*, FORMATTED_NUMBER, FORMATTED_NUMBER_EU*/]) &&
!this.singleSearchFlt) { !this.singleSearchFlt) {
// parseNb can return 0 for strings which are not // parseNb can return 0 for strings which are not
// formatted numbers, in that case return the original // formatted numbers, in that case return the original
// string. TODO: handle this in parseNb // string. TODO: handle this in parseNb
sA = parseNb(sA, nbFormat) || sA; sA = parseNb(sA, decimal) || sA;
occurence = numData === sA || occurence = numData === sA ||
contains(sA.toString(), numData.toString(), contains(sA.toString(), numData.toString(),
this.isExactMatch(colIdx), this.caseSensitive); this.isExactMatch(colIdx), this.caseSensitive);
@ -2179,17 +2159,19 @@ export class TableFilter {
continue; continue;
} }
let cellData = this.getCellData(cell[j]); let cellData = this.getCellData(cell[j]);
// let nbFormat = this.hasType(colIndex, // let decimal = this.hasType(colIndex,
// [FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) ? // [FORMATTED_NUMBER, FORMATTED_NUMBER_EU]) ?
// this.colTypes[colIndex] : undefined; // this.colTypes[colIndex] : undefined;
let decimal = this.decimalSeparator; let decimal = this.decimalSeparator;
if (this.hasType(colIndex, [NUMBER])) { if (this.hasType(colIndex, [FORMATTED_NUMBER])) {
let colType = this.colTypes[colIndex]; let colType = this.colTypes[colIndex];
if (colType.hasOwnProperty('decimal')) { if (colType.hasOwnProperty('decimal')) {
decimal = colType.decimal; decimal = colType.decimal;
} }
} }
let data = num ? parseNb(cellData, decimal) : cellData; let data = num ?
Number(cellData) || parseNb(cellData, decimal) :
cellData;
colValues.push(data); colValues.push(data);
} }
} }

View file

@ -52,9 +52,7 @@ var tfConfig = {
name: 'sort', name: 'sort',
types: [ types: [
'number', 'string', 'string', 'number', 'string', 'string',
{ type: 'number', decimal: '.' }, 'formatted-number', 'none', 'string'
// 'number',
'none', 'string'
] ]
} }
] ]

View file

@ -77,26 +77,24 @@ var tfConfig = {
col_types: [ col_types: [
'string', 'string', 'string', 'string', 'string', 'string',
{ {
type: 'number', decimal: ',', thousands: '.' type: 'formatted-number', decimal: ',', thousands: '.'
}, },
'formatted-number', 'string',
{ {
type: 'number', decimal: '.', thousands: ',' type: 'date', locale: 'fr'/*,
}, format: ['{dd}/{MM}/{yyyy}', '{dd}-{MM}-{yyyy|yy}']*/
'string',
{
type: 'date', locale: 'en',
format: ['{dd}/{MM}/{yyyy}', '{dd}-{MM}-{yyyy|yy}']
}, },
{ type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' }, { type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' },
{ type: 'date', locale: 'en', format: '{dd}-{months}-{yyyy|yy}' }, { type: 'date', locale: 'en', format: ['{dd}-{months}-{yyyy|yy}'] },
'ipaddress' 'ipaddress'
], ],
rows_always_visible: [totRowIndex], rows_always_visible: [totRowIndex],
on_filters_loaded: function(o){ on_filters_loaded: function(tf){
o.setFilterValue(3, '>1.000'); tf.setFilterValue(3, '>1.000');
o.setFilterValue(4, '<2,500'); tf.setFilterValue(4, '<2,500');
o.setFilterValue(6, '>23-01-95'); tf.setFilterValue(6, '>23-01-95');
o.filter(); tf.setFilterValue(8, '<2000');
tf.filter();
}, },
extensions:[ extensions:[
{ name: 'sort' }, { name: 'sort' },
@ -138,9 +136,9 @@ var tf2Config = {
'string', 'number', 'string', 'string', 'number', 'string',
'number', 'string', 'date' 'number', 'string', 'date'
], ],
on_filters_loaded: function(o){ on_filters_loaded: function(tf){
o.setFilterValue(5, '>95-05-18'); tf.setFilterValue(5, '>95-05-18');
o.filter(); tf.filter();
} }
}; };
var tf2 = new TableFilter('demo', tf2Config); var tf2 = new TableFilter('demo', tf2Config);