From d656ec90b093d3903d2d22b5f18b75ea3275f089 Mon Sep 17 00:00:00 2001 From: Max Guglielmi Date: Thu, 15 Sep 2016 23:39:43 +1000 Subject: [PATCH] Continued sort adapter --- dist/tablefilter/tablefilter.js | 19 +++++---- dist/tablefilter/tf-1.js | 45 ++++++++++++++++----- src/const.js | 4 +- src/extensions/sort/adapterSortabletable.js | 43 ++++++++++++++++---- src/modules/dateType.js | 13 +++--- 5 files changed, 90 insertions(+), 34 deletions(-) diff --git a/dist/tablefilter/tablefilter.js b/dist/tablefilter/tablefilter.js index 4ed68b98..ba6c5b88 100644 --- a/dist/tablefilter/tablefilter.js +++ b/dist/tablefilter/tablefilter.js @@ -3899,13 +3899,13 @@ return /******/ (function(modules) { // webpackBootstrap var FORMATTED_NUMBER_EU = exports.FORMATTED_NUMBER_EU = 'formatted-number-eu'; /** - *Date + * Date * @type {String} */ var DATE = exports.DATE = 'date'; /** - *IP address + * IP address * @type {String} */ var IP_ADDRESS = exports.IP_ADDRESS = 'ipaddress'; @@ -10203,7 +10203,7 @@ return /******/ (function(modules) { // webpackBootstrap // let locale = this.datetime.getLocale(this.locale); // Add formats from column types configuration if any - this._addConfigFormats(); + this.addConfigFormats(this.tf.colTypes); // locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{MM}/{dd}/{yyyy}'); // locale.addFormat('{dd}-{months}-{yyyy|yy}'); @@ -10226,16 +10226,19 @@ return /******/ (function(modules) { // webpackBootstrap return this.datetime.isValid(this.parse(dateStr, localeCode)); }; - DateType.prototype.getOptions = function getOptions(colIndex) { - var colType = this.tf.colTypes[colIndex]; + DateType.prototype.getOptions = function getOptions(colIndex, types) { + types = types || this.tf.colTypes; + var colType = types[colIndex]; return (0, _types.isObj)(colType) ? colType : {}; }; - DateType.prototype._addConfigFormats = function _addConfigFormats() { + DateType.prototype.addConfigFormats = function addConfigFormats() { var _this = this; - this.tf.colTypes.forEach(function (type, idx) { - var options = _this.getOptions(idx); + var types = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; + + types.forEach(function (type, idx) { + var options = _this.getOptions(idx, types); if (options.hasOwnProperty('format')) { (function () { var locale = _this.datetime.getLocale(options.locale || _this.locale); diff --git a/dist/tablefilter/tf-1.js b/dist/tablefilter/tf-1.js index 215e1b21..97b6fe80 100644 --- a/dist/tablefilter/tf-1.js +++ b/dist/tablefilter/tf-1.js @@ -2824,11 +2824,25 @@ webpackJsonp([1],{ sortTypes = this.sortTypes, _sortTypes = []; - for (var i = 0; i < tf.nbCells; i++) { + for (var i = 0; i < tf.getCellsNb(); i++) { var colType = void 0; if (sortTypes[i]) { - colType = sortTypes[i].toLowerCase(); + colType = sortTypes[i]; + if (isObj(colType)) { + // colType = colType.type; + if (colType.type === _const.DATE) { + // let dateType = tf.feature('dateType'); + // let locale=dateType.getOptions(i,sortTypes).locale || + // tf.locale; + // colType = `${DATE}-${locale}`; + // this.addSortType(colType, (dateStr) => { + // return dateType.parse(dateStr, locale); + // }); + colType = this._addDateType(i, sortTypes); + } + } + colType = colType.toLowerCase(); if (colType === _const.NONE) { colType = 'None'; } @@ -2839,14 +2853,13 @@ webpackJsonp([1],{ // } else if (tf.hasColDateType && tf.colDateType[i] !== null) { // colType = tf.colDateType[i].toLowerCase() + 'date'; } else if (tf.hasType(i, [_const.DATE])) { - (function () { - var dateType = tf.feature('dateType'); - var locale = dateType.getOptions(i).locale || tf.locale; - colType = _const.DATE + '-' + locale; - _this3.addSortType(colType, function (dateStr) { - return dateType.parse(dateStr, locale); - }); - })(); + // let dateType = tf.feature('dateType'); + // let locale = dateType.getOptions(i).locale || tf.locale; + // colType = `${DATE}-${locale}`; + // this.addSortType(colType, (dateStr) => { + // return dateType.parse(dateStr, locale); + // }); + colType = this._addDateType(i); } else { colType = _const.STRING; } @@ -2897,6 +2910,18 @@ webpackJsonp([1],{ } }; + AdapterSortableTable.prototype._addDateType = function _addDateType(colIndex, types) { + var tf = this.tf; + var dateType = tf.feature('dateType'); + var locale = dateType.getOptions(colIndex, types).locale || tf.locale; + var colType = _const.DATE + '-' + locale; + + this.addSortType(colType, function (dateStr) { + return dateType.parse(dateStr, locale); + }); + return colType; + }; + /** * Remove extension */ diff --git a/src/const.js b/src/const.js index 10b1ea99..d7ab4f0e 100644 --- a/src/const.js +++ b/src/const.js @@ -102,13 +102,13 @@ export const FORMATTED_NUMBER = 'formatted-number'; export const FORMATTED_NUMBER_EU = 'formatted-number-eu'; /** - *Date + * Date * @type {String} */ export const DATE = 'date'; /** - *IP address + * IP address * @type {String} */ export const IP_ADDRESS = 'ipaddress'; diff --git a/src/extensions/sort/adapterSortabletable.js b/src/extensions/sort/adapterSortabletable.js index b1639923..703a6d94 100644 --- a/src/extensions/sort/adapterSortabletable.js +++ b/src/extensions/sort/adapterSortabletable.js @@ -395,11 +395,25 @@ export default class AdapterSortableTable extends Feature { sortTypes = this.sortTypes, _sortTypes = []; - for (let i = 0; i < tf.nbCells; i++) { + for (let i = 0; i < tf.getCellsNb(); i++) { let colType; if (sortTypes[i]) { - colType = sortTypes[i].toLowerCase(); + colType = sortTypes[i]; + if (isObj(colType)) { + // colType = colType.type; + if (colType.type === DATE) { + // let dateType = tf.feature('dateType'); + // let locale=dateType.getOptions(i,sortTypes).locale || + // tf.locale; + // colType = `${DATE}-${locale}`; + // this.addSortType(colType, (dateStr) => { + // return dateType.parse(dateStr, locale); + // }); + colType = this._addDateType(i, sortTypes); + } + } + colType = colType.toLowerCase(); if (colType === NONE) { colType = 'None'; } @@ -410,12 +424,13 @@ export default class AdapterSortableTable extends Feature { // } else if (tf.hasColDateType && tf.colDateType[i] !== null) { // colType = tf.colDateType[i].toLowerCase() + 'date'; } else if (tf.hasType(i, [DATE])) { - let dateType = tf.feature('dateType'); - let locale = dateType.getOptions(i).locale || tf.locale; - colType = `${DATE}-${locale}`; - this.addSortType(colType, (dateStr) => { - return dateType.parse(dateStr, locale); - }); + // let dateType = tf.feature('dateType'); + // let locale = dateType.getOptions(i).locale || tf.locale; + // colType = `${DATE}-${locale}`; + // this.addSortType(colType, (dateStr) => { + // return dateType.parse(dateStr, locale); + // }); + colType = this._addDateType(i); } else { colType = STRING; } @@ -464,6 +479,18 @@ 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, (dateStr) => { + return dateType.parse(dateStr, locale); + }); + return colType; + } + /** * Remove extension */ diff --git a/src/modules/dateType.js b/src/modules/dateType.js index 741d7532..8f4dfea6 100644 --- a/src/modules/dateType.js +++ b/src/modules/dateType.js @@ -22,7 +22,7 @@ export class DateType { // let locale = this.datetime.getLocale(this.locale); // Add formats from column types configuration if any - this._addConfigFormats(); + this.addConfigFormats(this.tf.colTypes); // locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{MM}/{dd}/{yyyy}'); // locale.addFormat('{dd}-{months}-{yyyy|yy}'); @@ -45,14 +45,15 @@ export class DateType { return this.datetime.isValid(this.parse(dateStr, localeCode)); } - getOptions(colIndex) { - let colType = this.tf.colTypes[colIndex]; + getOptions(colIndex, types) { + types = types || this.tf.colTypes; + let colType = types[colIndex]; return isObj(colType) ? colType : {}; } - _addConfigFormats() { - this.tf.colTypes.forEach((type, idx) => { - let options = this.getOptions(idx); + addConfigFormats(types=[]) { + types.forEach((type, idx) => { + let options = this.getOptions(idx, types); if (options.hasOwnProperty('format')) { let locale = this.datetime.getLocale( options.locale || this.locale