Add support for column sorting

issue5675
review31301002
This commit is contained in:
Xavier Codinas
2016-08-08 17:08:16 +02:00
parent a077ee95eb
commit 11f1ecd8df
5 changed files with 75 additions and 5 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add support for column sorting
* Manage confirm attribute on buttons
* Call autocompletion when setting record value
* Limit readonly state for xxx2Many
+9
View File
@@ -437,6 +437,15 @@
};
return jQuery.when().then(browse_child);
};
array.sort = function(ids) {
var id2record = {};
this.forEach(function(record) {
id2record[record.id] = record;
});
ids.forEach(function(ordered_record, i){
this[i] = id2record[ordered_record.id];
}.bind(this));
};
return array;
};
+3
View File
@@ -62,6 +62,9 @@ button {
width: 30px;
}
& > thead > tr > th {
& > label.sortable {
cursor: pointer;
}
overflow: hidden;
text-overflow: ellipsis;
min-width: 30px;
+9 -4
View File
@@ -627,6 +627,7 @@
this.size_limit = null;
this.limit = attributes.limit || Sao.config.limit;
this.offset = 0;
this.order = attributes.order;
var access = Sao.common.MODELACCESS.get(model_name);
if (!(access.write || access.create)) {
this.attributes.readonly = true;
@@ -778,7 +779,8 @@
}.bind(this);
return _switch();
},
search_filter: function(search_string) {
search_filter: function(search_string, only_ids) {
only_ids = only_ids || false;
if (this.context_screen) {
if (this.context_screen_prm.state() == 'pending') {
return this.context_screen_prm.then(function() {
@@ -827,9 +829,12 @@
}
var grp_prm = this.model.find(domain, this.offset, this.limit,
this.attributes.order, this.context);
var count_prm = this.model.execute('search_count', [domain],
this.context);
this.order, this.context);
var count_prm = jQuery.when(this.search_count);
if (!only_ids) {
count_prm = this.model.execute('search_count', [domain],
this.context);
}
count_prm.done(function(count) {
this.search_count = count;
}.bind(this));
+53 -1
View File
@@ -100,6 +100,13 @@
label.addClass('editable');
}
}
if (column.sortable) {
var arrow = jQuery('<span/>');
label.append(arrow);
column.arrow = arrow;
th.click(column, this.sort_model.bind(this));
label.addClass('sortable');
}
tr.append(th.append(label));
column.header = th;
}, this);
@@ -191,7 +198,11 @@
affix_attributes));
}
}
if (!this.attributes.sequence &&
!this.children_field &&
model.fields[name].description.sortable !== false){
column.sortable = true;
}
this.fields[name] = true;
// TODO sum
} else if (child.tagName == 'button') {
@@ -201,6 +212,47 @@
this.columns.push(column);
}.bind(this));
},
sort_model: function(e){
var column = e.data;
var arrow = column.arrow;
var arrow_top = 'glyphicon glyphicon-triangle-top';
var arrow_bottom = 'glyphicon glyphicon-triangle-bottom';
this.columns.forEach(function(col) {
if (col.arrow){
if (col != column && col.arrow.hasClass('glyphicon')) {
col.arrow.removeClass(arrow_top + ' ' + arrow_bottom);
}
}
});
this.screen.order = null;
if (arrow.hasClass(arrow_bottom)) {
arrow.removeClass(arrow_bottom);
arrow.addClass(arrow_top);
this.screen.order = [[column.attributes.name, 'DESC']];
} else if (arrow.hasClass(arrow_top)) {
arrow.removeClass(arrow_top);
} else {
arrow.addClass(arrow_bottom);
this.screen.order = [[column.attributes.name, 'ASC']];
}
var unsaved_records = [];
this.screen.group.forEach(function(unsaved_record) {
if (unsaved_record.id < 0) {
unsaved_records = unsaved_record.group;
}
});
var search_string = this.screen.screen_container.get_text();
if ((!jQuery.isEmptyObject(unsaved_records)) ||
(this.screen.search_count == this.screen.group.length) ||
(this.screen.parent)) {
this.screen.search_filter(search_string, true).then(
function(ids) {
this.screen.group.sort(ids);
}.bind(this));
} else {
this.screen.search_filter(search_string);
}
},
get_buttons: function() {
var buttons = [];
this.columns.forEach(function(column) {