textlist improvements (keep selection after sort, make left/right arrows scroll left/right)
This commit is contained in:
parent
32b2da184a
commit
187adae7e2
3 changed files with 64 additions and 17 deletions
|
|
@ -58,7 +58,17 @@ Ox.TextList = function(options, self) {
|
|||
sort: []
|
||||
})
|
||||
.options(options || {})
|
||||
.addClass('OxTextList');
|
||||
.addClass('OxTextList')
|
||||
.bindEvent({
|
||||
key_left: function() {
|
||||
var $element = that.$body.$element;
|
||||
$element[0].scrollLeft = $element[0].scrollLeft - $element.width();
|
||||
},
|
||||
key_right: function() {
|
||||
var $element = that.$body.$element;
|
||||
$element[0].scrollLeft = $element[0].scrollLeft + $element.width();
|
||||
}
|
||||
});
|
||||
|
||||
self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function?
|
||||
// fixme: and can't these just remain undefined?
|
||||
|
|
@ -254,15 +264,19 @@ Ox.TextList = function(options, self) {
|
|||
Ox.print('clickColumn', id);
|
||||
var i = getColumnIndexById(id),
|
||||
isSelected = self.options.sort[0].key == self.options.columns[i].id;
|
||||
that.$body.options({
|
||||
sort: [{
|
||||
key: self.options.columns[i].id,
|
||||
operator: isSelected ?
|
||||
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
||||
self.options.columns[i].operator,
|
||||
map: self.options.columns[i].map
|
||||
}]
|
||||
});
|
||||
self.options.sort = [{
|
||||
key: self.options.columns[i].id,
|
||||
operator: isSelected ?
|
||||
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
||||
self.options.columns[i].operator,
|
||||
map: self.options.columns[i].map
|
||||
}]
|
||||
updateColumn();
|
||||
// fixme: strangely, sorting the list blocks updating the column,
|
||||
// so we use a timeout for now
|
||||
setTimeout(function() {
|
||||
that.$body.options({sort: self.options.sort});
|
||||
}, 10)
|
||||
}
|
||||
|
||||
function constructHead() {
|
||||
|
|
@ -622,6 +636,20 @@ Ox.TextList = function(options, self) {
|
|||
});
|
||||
}
|
||||
|
||||
function updateColumn() {
|
||||
var columnId = self.options.columns[self.selectedColumn].id
|
||||
isSelected = columnId == self.options.sort[0].key;
|
||||
if (self.options.columnsVisible) {
|
||||
if (isSelected) {
|
||||
updateOrder(columnId);
|
||||
} else {
|
||||
toggleSelected(columnId);
|
||||
self.selectedColumn = getColumnIndexById(self.options.sort[0].key);
|
||||
toggleSelected(self.options.columns[self.selectedColumn].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateOrder(id) {
|
||||
var pos = getColumnPositionById(id);
|
||||
//Ox.print(id, pos)
|
||||
|
|
@ -638,6 +666,9 @@ Ox.TextList = function(options, self) {
|
|||
that.$body.options(key, value);
|
||||
} else if (key == 'selected') {
|
||||
that.$body.options(key, value);
|
||||
} else if (key == 'sort') {
|
||||
updateColumn();
|
||||
that.$body.options(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -731,7 +762,9 @@ Ox.TextList = function(options, self) {
|
|||
that.$body.size();
|
||||
}
|
||||
|
||||
// fixme: deprecated
|
||||
that.sortList = function(key, operator) {
|
||||
Ox.print('$$$$ DEPRECATED $$$$')
|
||||
var isSelected = key == self.options.sort[0].key;
|
||||
self.options.sort = [{
|
||||
key: key,
|
||||
|
|
@ -750,11 +783,14 @@ Ox.TextList = function(options, self) {
|
|||
// fixme: strangely, sorting the list blocks toggling the selection,
|
||||
// so we use a timeout for now
|
||||
setTimeout(function() {
|
||||
that.$body.options({sort: self.options.sort});
|
||||
/*
|
||||
that.$body.sortList(
|
||||
self.options.sort[0].key,
|
||||
self.options.sort[0].operator,
|
||||
self.options.sort[0].map
|
||||
);
|
||||
*/
|
||||
}, 10);
|
||||
return that;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue