make list preserve selection after reload
This commit is contained in:
parent
5790a5695e
commit
8dc0c02dfb
1 changed files with 32 additions and 23 deletions
|
@ -2377,7 +2377,6 @@ requires
|
|||
itemHeight: 16,
|
||||
itemWidth: 16,
|
||||
keys: [],
|
||||
listLength: 0,
|
||||
orientation: "vertical",
|
||||
request: function() {}, // {sort:, range:, callback:}, without parameter returns {items, size etc.}
|
||||
rowLength: 1,
|
||||
|
@ -2542,7 +2541,6 @@ requires
|
|||
offset = page * self.pageLength,
|
||||
range = [offset, offset + (page < self.pages - 1 ?
|
||||
self.pageLength : self.listLength % self.pageLength)];
|
||||
Ox.print("keys", keys)
|
||||
if (Ox.isUndefined(self.$pages[page])) {
|
||||
self.requests.push(self.options.request({
|
||||
callback: function(result) {
|
||||
|
@ -2696,41 +2694,52 @@ requires
|
|||
};
|
||||
|
||||
that.reload = function() {
|
||||
|
||||
$.each(self.requests, function(i, v) {
|
||||
Ox.Request.cancel(v);
|
||||
});
|
||||
self.requests = [];
|
||||
if (self.selected.length) {
|
||||
$.extend(self, {
|
||||
$items: [],
|
||||
$pages: [],
|
||||
page: 0,
|
||||
requests: []
|
||||
});
|
||||
|
||||
// fixme: optimize: send non-selected ids if more than half of the items are selected
|
||||
Ox.print(self.selected.length, self.listLength);
|
||||
if (self.selected.length && self.selected.length < self.listLength) {
|
||||
Ox.print("sort", self.options.sort, "ids", $.map(self.selected, function(v, i) {
|
||||
return self.ids[v];
|
||||
}));
|
||||
self.requests.push(self.options.request({
|
||||
callback: function(result) {
|
||||
self.selected = [];
|
||||
$.each(result.data.positions, function(id, pos) {
|
||||
Ox.print("id", id, "pos", pos)
|
||||
self.selected.push(pos);
|
||||
addToSelection(pos);
|
||||
});
|
||||
},
|
||||
callback: callback,
|
||||
ids: $.map(self.selected, function(v, i) {
|
||||
return self.ids[v];
|
||||
}),
|
||||
sort: self.options.sort
|
||||
}));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
function callback(result) {
|
||||
if (result) {
|
||||
$.extend(self, {
|
||||
$items: [],
|
||||
$pages: [],
|
||||
ids: {},
|
||||
page: 0,
|
||||
selected: []
|
||||
});
|
||||
$.each(result.data.positions, function(id, pos) {
|
||||
Ox.print("id", id, "pos", pos)
|
||||
self.selected.push(pos);
|
||||
});
|
||||
}
|
||||
that.$content.empty();
|
||||
that.scrollTop(0);
|
||||
loadPages(self.page);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
that.sort = function(key, operator) {
|
||||
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
||||
self.options.sort[0] = {
|
||||
|
|
Loading…
Reference in a new issue