In Ox.TableList, add a 'sort' property for columns (a function with two arguments, the item's value for this column and the full item object), so that the sort order can now depend on other keys (and we can abandon the pattern of passing the sort value as value and a complicated format function to get the actual value)

This commit is contained in:
rolux 2012-09-03 22:26:27 +02:00
parent 8407a88af1
commit a3ddc7c2d4

View file

@ -7,12 +7,14 @@ Ox.TableList <f> TableList Widget
clearButtonTooltip <s|''> Clear button tooltip clearButtonTooltip <s|''> Clear button tooltip
columns <[o]|[]> Columns columns <[o]|[]> Columns
# Fixme: There's probably more... # Fixme: There's probably more...
align <s|'left'> ...
editable <b> ... editable <b> ...
format <f> ... format <f> ...
id <s> ... id <s> ...
removable <b> ...
map <f> function that maps values to sort values
operator <s> default sort operator operator <s> default sort operator
removable <b> ...
resizable <b> ...
sort <f> function(value, object) that maps values to sort values
title <s> ... title <s> ...
titleImage <s> ... titleImage <s> ...
unformat <f> Applied before editing unformat <f> Applied before editing
@ -173,10 +175,14 @@ Ox.TableList = function(options, self) {
}); });
self.format = {}; self.format = {};
self.map = {};
self.options.columns.forEach(function(column) { self.options.columns.forEach(function(column) {
if (column.format) { if (column.format) {
self.format[column.id] = column.format; self.format[column.id] = column.format;
} }
if (column.sort) {
self.map[column.id] = column.sort;
}
}); });
// Head // Head
@ -261,6 +267,7 @@ Ox.TableList = function(options, self) {
.concat(self.options.unique) .concat(self.options.unique)
.concat(self.options.keys) .concat(self.options.keys)
), ),
map: self.map,
max: self.options.max, max: self.options.max,
min: self.options.min, min: self.options.min,
orientation: 'vertical', orientation: 'vertical',
@ -366,8 +373,7 @@ Ox.TableList = function(options, self) {
key: self.options.columns[i].id, key: self.options.columns[i].id,
operator: isSelected ? operator: isSelected ?
(self.options.sort[0].operator == '+' ? '-' : '+') : (self.options.sort[0].operator == '+' ? '-' : '+') :
self.options.columns[i].operator, self.options.columns[i].operator
map: self.options.columns[i].map
}]; }];
updateColumn(); updateColumn();
// fixme: strangely, sorting the list blocks updating the column, // fixme: strangely, sorting the list blocks updating the column,
@ -505,9 +511,9 @@ Ox.TableList = function(options, self) {
$cell = $('<div>'); $cell = $('<div>');
} }
$cell.addClass( $cell.addClass(
'OxCell OxColumn' + Ox.toTitleCase(v.id) + 'OxCell OxColumn' + Ox.toTitleCase(v.id)
(clickable ? ' OxClickable' : '') + + (clickable ? ' OxClickable' : '')
(editable ? ' OxEditable' : '') + (editable ? ' OxEditable' : '')
) )
.css({ .css({
width: (self.columnWidths[i] - (self.options.columnsVisible ? 9 : 8)) + 'px', width: (self.columnWidths[i] - (self.options.columnsVisible ? 9 : 8)) + 'px',