Skip to content

Commit

Permalink
Preserve selection in folder contents when scolling causes ajax reque…
Browse files Browse the repository at this point in the history
…st. (Pylons#95)
  • Loading branch information
Daniel Havlik committed Aug 15, 2013
1 parent 4e23f0a commit 372bc53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Unreleased
----------

- Initial release.
- Fixed #95 (When the scrolling causes an ajax request the selections are
lost.)
21 changes: 12 additions & 9 deletions substanced/sdi/static/js/sdi.grid.remotemodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

var grid;
var data;
var ids_to_data_key = {}; // maps row id (like "document_0") to data key
var activeRequest;
var scrollPosition; // scrolling movement (prefetch) forward or backward

Expand Down Expand Up @@ -256,6 +257,7 @@
// make sure not to go beyond the total, most specifically,
// do not do any fetch _beyond_ the total.
data.length = null;
ids_to_data_key = {};
}

function clearData(/*optional*/ scrollToTop) {
Expand All @@ -277,6 +279,9 @@
//log('loadData', from, to, to - from);
for (i = from; i < to; i++) {
data[i] = _data.records[i - from];
if (data[i] !== undefined) {
ids_to_data_key[data[i].id] = i;
}
}
data.length = _data.total;
// Update the grid.
Expand Down Expand Up @@ -451,17 +456,15 @@
return ids;
}

function mapIdsToRows(ids, from, to) {
function mapIdsToRows(ids) {
var rows = [];
var i;
//log('mapIdsToRows', from, to, data[from]);
for (i = from; i < to; i++) {
if (data[i] !== undefined) {
if (ids[data[i].id]) {
rows.push(i);
}
$.each(ids, function(key, item) {
var data_key = ids_to_data_key[key];
if (data[data_key] !== undefined) {
rows.push(data_key);
}
}
});
return rows;
}

Expand All @@ -483,7 +486,7 @@
if (args.from !== undefined) {
// restore selections
inHandler = true;
var selectedRows = mapIdsToRows(selectedRowIds, args.from, args.to);
var selectedRows = mapIdsToRows(selectedRowIds);
if (! preserveHidden) {
selectedRowIds = mapRowsToIds(selectedRows);
}
Expand Down

0 comments on commit 372bc53

Please sign in to comment.