mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-16 23:55:46 +01:00
Enhance filter options sorting based on column data type
This commit is contained in:
parent
2e1af5efb3
commit
78ae09c861
12 changed files with 151 additions and 50 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import {Feature} from '../feature';
|
||||
import {
|
||||
ignoreCase, numSortAsc, numSortDesc,
|
||||
dateSortAsc, sortNumberStr, sortDateStr
|
||||
dateSortAsc, dateSortDesc, sortNumberStr, sortDateStr
|
||||
} from '../sort';
|
||||
import {isArray, isObj, isEmpty} from '../types';
|
||||
import {NUMBER, FORMATTED_NUMBER, DATE} from '../const';
|
||||
|
|
@ -72,14 +72,15 @@ export class BaseDropdown extends Feature {
|
|||
* @private
|
||||
*/
|
||||
sortOptions(colIndex, options = []) {
|
||||
let tf = this.tf;
|
||||
let {tf} = this;
|
||||
|
||||
if (tf.isCustomOptions(colIndex) || !tf.sortSlc ||
|
||||
(isArray(tf.sortSlc) && tf.sortSlc.indexOf(colIndex) === -1)) {
|
||||
return options;
|
||||
}
|
||||
|
||||
let { caseSensitive, sortNumDesc } = tf;
|
||||
let { caseSensitive, sortFilterOptionsDesc } = tf;
|
||||
let isSortDesc = sortFilterOptionsDesc.indexOf(colIndex) !== -1;
|
||||
let compareFn;
|
||||
|
||||
if (this.customSorter &&
|
||||
|
|
@ -89,18 +90,18 @@ export class BaseDropdown extends Feature {
|
|||
}
|
||||
else if (tf.hasType(colIndex, [NUMBER, FORMATTED_NUMBER])) {
|
||||
let decimal = tf.getDecimal(colIndex);
|
||||
let comparer = numSortAsc;
|
||||
if (sortNumDesc === true || sortNumDesc.indexOf(colIndex) !== -1) {
|
||||
comparer = numSortDesc;
|
||||
}
|
||||
let comparer = isSortDesc ? numSortDesc : numSortAsc;
|
||||
compareFn = sortNumberStr(comparer, decimal);
|
||||
}
|
||||
else if (tf.hasType(colIndex, [DATE])) {
|
||||
let locale = tf.feature('dateType').getLocale(colIndex);
|
||||
let comparer = dateSortAsc;
|
||||
let comparer = isSortDesc ? dateSortDesc : dateSortAsc;
|
||||
compareFn = sortDateStr(comparer, locale);
|
||||
} else { // string
|
||||
compareFn = caseSensitive ? undefined : ignoreCase;
|
||||
if (isSortDesc) {
|
||||
return options.sort(compareFn).reverse();
|
||||
}
|
||||
}
|
||||
|
||||
return options.sort(compareFn);
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ export class TableFilter {
|
|||
this.onAfterFilter = defaultsFn(f.on_after_filter, EMPTY_FN);
|
||||
|
||||
/**
|
||||
* Enable/disable case sensitivity filtering
|
||||
* Enable/disable case sensitivity for filtering, default false
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.caseSensitive = Boolean(f.case_sensitive);
|
||||
|
|
@ -534,38 +534,24 @@ export class TableFilter {
|
|||
* by default globally or on a column basis
|
||||
* @type {Boolean|Array}
|
||||
*/
|
||||
this.sortSlc = isUndef(f.sort_select) ? true :
|
||||
isArray(f.sort_select) ? f.sort_select : Boolean(f.sort_select);
|
||||
this.sortSlc = isUndef(f.sort_select)
|
||||
? true
|
||||
: defaultsArr(f.sort_select, Boolean(f.sort_select));
|
||||
|
||||
/**
|
||||
* Indicate whether options in drop-down filter types are sorted in a
|
||||
* ascending numeric manner
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.isSortNumAsc = Boolean(f.sort_num_asc);
|
||||
|
||||
/**
|
||||
* List of columns implementing options sorting in a ascending numeric
|
||||
* manner
|
||||
* List of columns implementing filter options sorting in ascending
|
||||
* manner based on column data type
|
||||
* @type {Array}
|
||||
*/
|
||||
this.sortNumAsc = this.isSortNumAsc ? f.sort_num_asc : [];
|
||||
this.sortFilterOptionsAsc = defaultsArr(f.sort_filter_options_asc, []);
|
||||
|
||||
/**
|
||||
* Indicate whether options in drop-down filter types are sorted in a
|
||||
* descending numeric manner
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this.isSortNumDesc = Boolean(f.sort_num_desc);
|
||||
|
||||
/**
|
||||
* List of columns implementing options sorting in a descending numeric
|
||||
* manner
|
||||
* List of columns implementing filter options sorting in descending
|
||||
* manner based on column data type
|
||||
* @type {Array}
|
||||
*/
|
||||
this.sortNumDesc = this.isSortNumDesc ? f.sort_num_desc : [];
|
||||
this.sortFilterOptionsDesc =
|
||||
defaultsArr(f.sort_filter_options_desc, []);
|
||||
|
||||
/**
|
||||
* Indicate whether drop-down filter types are populated on demand at
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue