forked from 0x2620/oxjs
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
|
|
@ -556,7 +556,7 @@ Ox.List = function(options, self) {
|
|||
}
|
||||
|
||||
function getPositions(ids) {
|
||||
Ox.print('getPositions', ids)
|
||||
// Ox.print('getPositions', ids)
|
||||
ids = ids || getSelectedIds();
|
||||
Ox.print('getPositions', ids)
|
||||
// fixme: optimize: send non-selected ids if more than half of the items are selected
|
||||
|
|
@ -628,7 +628,7 @@ Ox.List = function(options, self) {
|
|||
function getSelectedIds() {
|
||||
//Ox.print('gSI', self.selected, self.$items)
|
||||
return $.map(self.selected, function(pos) {
|
||||
Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique])
|
||||
//Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique])
|
||||
//Ox.print('2222', self.$items, pos)
|
||||
return self.$items[pos].options('data')[self.options.unique];
|
||||
});
|
||||
|
|
@ -662,6 +662,7 @@ Ox.List = function(options, self) {
|
|||
isSelected(pos) && self.$items[pos].addClass('OxSelected');
|
||||
self.$items[pos].appendTo(that.$content);
|
||||
});
|
||||
self.selected.length && scrollToPosition(self.selected[0]);
|
||||
}
|
||||
|
||||
function getPageLength(page) {
|
||||
|
|
@ -1230,14 +1231,16 @@ Ox.List = function(options, self) {
|
|||
function updateSort() {
|
||||
Ox.print('start sort')
|
||||
var key = self.options.sort[0].key,
|
||||
operator = self.options.sort[0].operator,
|
||||
map = self.options.sort[0].map,
|
||||
operator = self.options.sort[0].operator,
|
||||
selectedIds,
|
||||
sort = {};
|
||||
self.options.items.forEach(function(item) {
|
||||
sort[item.id] = map ? map(item[key]) : item[key];
|
||||
});
|
||||
if (self.listLength > 1) {
|
||||
if (Ox.isArray(self.options.items)) {
|
||||
selectedIds = getSelectedIds();
|
||||
self.options.items.forEach(function(item) {
|
||||
sort[item.id] = map ? map(item[key]) : item[key];
|
||||
});
|
||||
self.options.items.sort(function(a, b) {
|
||||
var aValue = sort[a.id],
|
||||
bValue = sort[b.id],
|
||||
|
|
@ -1249,6 +1252,14 @@ Ox.List = function(options, self) {
|
|||
}
|
||||
return ret;
|
||||
});
|
||||
if (selectedIds.length) {
|
||||
self.selected = [];
|
||||
self.options.items.forEach(function(item, i) {
|
||||
if (selectedIds.indexOf(item.id) > -1) {
|
||||
self.selected.push(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
loadItems();
|
||||
} else {
|
||||
clear(); // fixme: bad function name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue