forked from 0x2620/oxjs
add an optional function to textlist columns that maps values to sort values
This commit is contained in:
parent
5915acd72c
commit
a3c18e57b0
6 changed files with 34 additions and 16 deletions
|
|
@ -45,14 +45,11 @@ Ox.List = function(options, self) {
|
|||
that = new Ox.Container({}, self)
|
||||
.defaults({
|
||||
centered: false,
|
||||
|
||||
construct: null,
|
||||
draggable: false,
|
||||
format: [],
|
||||
itemHeight: 16,
|
||||
items: null,
|
||||
|
||||
|
||||
itemWidth: 16,
|
||||
keys: [],
|
||||
max: -1,
|
||||
|
|
@ -1217,16 +1214,18 @@ Ox.List = function(options, self) {
|
|||
}));
|
||||
}
|
||||
|
||||
function updateSort() {
|
||||
function updateSort(map) {
|
||||
var key = self.options.sort[0].key,
|
||||
operator = self.options.sort[0].operator;
|
||||
if (self.listLength > 1) {
|
||||
if (Ox.isArray(self.options.items)) {
|
||||
self.options.items.sort(function(a, b) {
|
||||
var ret = 0
|
||||
if (a[key] < b[key]) {
|
||||
var aValue = map ? map(a[key]) : a[key],
|
||||
bValue = map ? map(b[key]) : b[key],
|
||||
ret = 0
|
||||
if (aValue < bValue) {
|
||||
return operator == '+' ? -1 : 1
|
||||
} else if (a[key] > b[key]) {
|
||||
} else if (aValue > bValue) {
|
||||
return operator == '+' ? 1 : -1;
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -1468,12 +1467,13 @@ Ox.List = function(options, self) {
|
|||
(key, operator) -> <f> returns List Element
|
||||
key <s> key to sort list by
|
||||
operator <s> +/- sort ascending or descending
|
||||
map <f> function that maps values to sort values
|
||||
@*/
|
||||
that.sortList = function(key, operator) {
|
||||
that.sortList = function(key, operator, map) {
|
||||
Ox.print('sortList', key, operator)
|
||||
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
||||
self.options.sort[0] = {key: key, operator: operator};
|
||||
updateSort();
|
||||
updateSort(map);
|
||||
that.triggerEvent('sort', self.options.sort[0]);
|
||||
}
|
||||
return that;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue