Skip to content

Commit 24868ae

Browse files
author
Olivier Giulieri
committed
Preserve list selection while sorting.
1 parent 73d0142 commit 24868ae

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

dist/evolutility.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,21 @@ Evol.ViewMany = Backbone.View.extend({
932932
return [];
933933
},
934934

935+
setSelection: function(sel){
936+
// - param: sel = array of ids like ['1','2']
937+
if(this.options.selectable){
938+
if(sel.length>0){
939+
// TODO optimize and uncheck prev checked
940+
var selector = [];
941+
_.each(sel, function(id){
942+
selector.push('[data-mid='+id+'] .list-sel');
943+
});
944+
this.$(selector.join(',')).prop('checked', true);
945+
}
946+
}
947+
return this;
948+
},
949+
935950
pageSummary: function (pIdx, pSize, cSize) {
936951
if (cSize === 0) {
937952
return '';
@@ -994,6 +1009,7 @@ Evol.ViewMany = Backbone.View.extend({
9941009
var collec = this.collection,
9951010
ft = Evol.Dico.fieldTypes;
9961011
if(!_.isUndefined(collec)){
1012+
var sel = this.getSelection();
9971013
if(f.type==ft.text || f.type==ft.textml || f.type==ft.email){
9981014
collec.comparator = Evol.Dico.bbComparatorText(f.id);
9991015
}else if(f.value){
@@ -1010,10 +1026,12 @@ Evol.ViewMany = Backbone.View.extend({
10101026
if(!noRemember){
10111027
localStorage.setItem(this.uiModel.id+'-sort', f.id+'-'+direction);
10121028
}
1029+
this.setSelection(sel);
10131030
if(!noTrigger){
10141031
this.$el.trigger('list.sort', {id: f.id, direction:direction});
10151032
}
10161033
}
1034+
return this;
10171035
},
10181036

10191037
getItemRoute: function(){

0 commit comments

Comments
 (0)