1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-29 10:50:51 +02:00

Continued sort adapter

This commit is contained in:
Max Guglielmi 2016-09-15 23:39:43 +10:00
parent c70aa29523
commit d656ec90b0
5 changed files with 90 additions and 34 deletions

View file

@ -3899,13 +3899,13 @@ return /******/ (function(modules) { // webpackBootstrap
var FORMATTED_NUMBER_EU = exports.FORMATTED_NUMBER_EU = 'formatted-number-eu'; var FORMATTED_NUMBER_EU = exports.FORMATTED_NUMBER_EU = 'formatted-number-eu';
/** /**
*Date * Date
* @type {String} * @type {String}
*/ */
var DATE = exports.DATE = 'date'; var DATE = exports.DATE = 'date';
/** /**
*IP address * IP address
* @type {String} * @type {String}
*/ */
var IP_ADDRESS = exports.IP_ADDRESS = 'ipaddress'; var IP_ADDRESS = exports.IP_ADDRESS = 'ipaddress';
@ -10203,7 +10203,7 @@ return /******/ (function(modules) { // webpackBootstrap
// let locale = this.datetime.getLocale(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.addConfigFormats(this.tf.colTypes);
// locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{dd}/{MM}/{yyyy}');
// locale.addFormat('{MM}/{dd}/{yyyy}'); // locale.addFormat('{MM}/{dd}/{yyyy}');
// locale.addFormat('{dd}-{months}-{yyyy|yy}'); // locale.addFormat('{dd}-{months}-{yyyy|yy}');
@ -10226,16 +10226,19 @@ return /******/ (function(modules) { // webpackBootstrap
return this.datetime.isValid(this.parse(dateStr, localeCode)); return this.datetime.isValid(this.parse(dateStr, localeCode));
}; };
DateType.prototype.getOptions = function getOptions(colIndex) { DateType.prototype.getOptions = function getOptions(colIndex, types) {
var colType = this.tf.colTypes[colIndex]; types = types || this.tf.colTypes;
var colType = types[colIndex];
return (0, _types.isObj)(colType) ? colType : {}; return (0, _types.isObj)(colType) ? colType : {};
}; };
DateType.prototype._addConfigFormats = function _addConfigFormats() { DateType.prototype.addConfigFormats = function addConfigFormats() {
var _this = this; var _this = this;
this.tf.colTypes.forEach(function (type, idx) { var types = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var options = _this.getOptions(idx);
types.forEach(function (type, idx) {
var options = _this.getOptions(idx, types);
if (options.hasOwnProperty('format')) { if (options.hasOwnProperty('format')) {
(function () { (function () {
var locale = _this.datetime.getLocale(options.locale || _this.locale); var locale = _this.datetime.getLocale(options.locale || _this.locale);

View file

@ -2824,11 +2824,25 @@ webpackJsonp([1],{
sortTypes = this.sortTypes, sortTypes = this.sortTypes,
_sortTypes = []; _sortTypes = [];
for (var i = 0; i < tf.nbCells; i++) { for (var i = 0; i < tf.getCellsNb(); i++) {
var colType = void 0; var colType = void 0;
if (sortTypes[i]) { 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) { if (colType === _const.NONE) {
colType = 'None'; colType = 'None';
} }
@ -2839,14 +2853,13 @@ webpackJsonp([1],{
// } else if (tf.hasColDateType && tf.colDateType[i] !== null) { // } else if (tf.hasColDateType && tf.colDateType[i] !== null) {
// colType = tf.colDateType[i].toLowerCase() + 'date'; // colType = tf.colDateType[i].toLowerCase() + 'date';
} else if (tf.hasType(i, [_const.DATE])) { } else if (tf.hasType(i, [_const.DATE])) {
(function () { // let dateType = tf.feature('dateType');
var dateType = tf.feature('dateType'); // let locale = dateType.getOptions(i).locale || tf.locale;
var locale = dateType.getOptions(i).locale || tf.locale; // colType = `${DATE}-${locale}`;
colType = _const.DATE + '-' + locale; // this.addSortType(colType, (dateStr) => {
_this3.addSortType(colType, function (dateStr) { // return dateType.parse(dateStr, locale);
return dateType.parse(dateStr, locale); // });
}); colType = this._addDateType(i);
})();
} else { } else {
colType = _const.STRING; 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 * Remove extension
*/ */

View file

@ -102,13 +102,13 @@ export const FORMATTED_NUMBER = 'formatted-number';
export const FORMATTED_NUMBER_EU = 'formatted-number-eu'; export const FORMATTED_NUMBER_EU = 'formatted-number-eu';
/** /**
*Date * Date
* @type {String} * @type {String}
*/ */
export const DATE = 'date'; export const DATE = 'date';
/** /**
*IP address * IP address
* @type {String} * @type {String}
*/ */
export const IP_ADDRESS = 'ipaddress'; export const IP_ADDRESS = 'ipaddress';

View file

@ -395,11 +395,25 @@ export default class AdapterSortableTable extends Feature {
sortTypes = this.sortTypes, sortTypes = this.sortTypes,
_sortTypes = []; _sortTypes = [];
for (let i = 0; i < tf.nbCells; i++) { for (let i = 0; i < tf.getCellsNb(); i++) {
let colType; let colType;
if (sortTypes[i]) { 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) { if (colType === NONE) {
colType = 'None'; colType = 'None';
} }
@ -410,12 +424,13 @@ export default class AdapterSortableTable extends Feature {
// } else if (tf.hasColDateType && tf.colDateType[i] !== null) { // } else if (tf.hasColDateType && tf.colDateType[i] !== null) {
// colType = tf.colDateType[i].toLowerCase() + 'date'; // colType = tf.colDateType[i].toLowerCase() + 'date';
} else if (tf.hasType(i, [DATE])) { } else if (tf.hasType(i, [DATE])) {
let dateType = tf.feature('dateType'); // let dateType = tf.feature('dateType');
let locale = dateType.getOptions(i).locale || tf.locale; // let locale = dateType.getOptions(i).locale || tf.locale;
colType = `${DATE}-${locale}`; // colType = `${DATE}-${locale}`;
this.addSortType(colType, (dateStr) => { // this.addSortType(colType, (dateStr) => {
return dateType.parse(dateStr, locale); // return dateType.parse(dateStr, locale);
}); // });
colType = this._addDateType(i);
} else { } else {
colType = STRING; 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 * Remove extension
*/ */

View file

@ -22,7 +22,7 @@ export class DateType {
// let locale = this.datetime.getLocale(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.addConfigFormats(this.tf.colTypes);
// locale.addFormat('{dd}/{MM}/{yyyy}'); // locale.addFormat('{dd}/{MM}/{yyyy}');
// locale.addFormat('{MM}/{dd}/{yyyy}'); // locale.addFormat('{MM}/{dd}/{yyyy}');
// locale.addFormat('{dd}-{months}-{yyyy|yy}'); // locale.addFormat('{dd}-{months}-{yyyy|yy}');
@ -45,14 +45,15 @@ export class DateType {
return this.datetime.isValid(this.parse(dateStr, localeCode)); return this.datetime.isValid(this.parse(dateStr, localeCode));
} }
getOptions(colIndex) { getOptions(colIndex, types) {
let colType = this.tf.colTypes[colIndex]; types = types || this.tf.colTypes;
let colType = types[colIndex];
return isObj(colType) ? colType : {}; return isObj(colType) ? colType : {};
} }
_addConfigFormats() { addConfigFormats(types=[]) {
this.tf.colTypes.forEach((type, idx) => { types.forEach((type, idx) => {
let options = this.getOptions(idx); let options = this.getOptions(idx, types);
if (options.hasOwnProperty('format')) { if (options.hasOwnProperty('format')) {
let locale = this.datetime.getLocale( let locale = this.datetime.getLocale(
options.locale || this.locale options.locale || this.locale