[IMP] web: add auto sorting on pivot view
We add the attribute default_order on the pivot view (already present in graph view), this attribute will sort the pivot view on the given measure. Closes: #25675
This commit is contained in:
@@ -238,9 +238,12 @@ var PivotModel = AbstractModel.extend({
|
||||
* @param {string[]} params.colGroupBys
|
||||
* @param {string[]} params.measures
|
||||
* @param {Object} params.fields
|
||||
* @param {string} params.default_order
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
load: function (params) {
|
||||
var self = this;
|
||||
|
||||
this.initialDomain = params.domain;
|
||||
this.initialRowGroupBys = params.context.pivot_row_groupby || params.rowGroupBys;
|
||||
this.fields = params.fields;
|
||||
@@ -254,7 +257,13 @@ var PivotModel = AbstractModel.extend({
|
||||
sorted_column: {},
|
||||
};
|
||||
this.defaultGroupedBy = params.groupedBy;
|
||||
return this._loadData();
|
||||
|
||||
return this._loadData().then(function () {
|
||||
if (params.default_order) {
|
||||
var info = params.default_order.split(' ');
|
||||
self.sortRows(self.data.main_col.root.id, info[0], info[1] === 'desc');
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
|
||||
@@ -95,6 +95,7 @@ var PivotView = AbstractView.extend({
|
||||
this.loadParams.colGroupBys = colGroupBys;
|
||||
this.loadParams.rowGroupBys = rowGroupBys;
|
||||
this.loadParams.fields = this.fields;
|
||||
this.loadParams.default_order = params.default_order || this.arch.attrs.default_order;
|
||||
|
||||
this.controllerParams.title = params.title || this.arch.attrs.string || _t("Untitled");
|
||||
this.controllerParams.enableLinking = !this.arch.attrs.disable_linking;
|
||||
|
||||
@@ -1202,4 +1202,22 @@ QUnit.module('Views', {
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('pivot view should use default order for auto sorting', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: this.data,
|
||||
arch: '<pivot default_order="foo asc">' +
|
||||
'<field name="foo" type="measure"/>' +
|
||||
'</pivot>',
|
||||
});
|
||||
|
||||
assert.ok(pivot.$('thead tr:last th:last').hasClass('o_pivot_measure_row_sorted_asc'),
|
||||
"Last thead should be sorted in ascending order");
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
});});
|
||||
|
||||
@@ -826,6 +826,15 @@ element is ``<pivot>`` which can take the following attributes:
|
||||
Set to ``True`` to remove table cell's links to list view.
|
||||
``display_quantity``
|
||||
Set to ``true`` to display the Quantity column by default.
|
||||
``default_order``
|
||||
The name of the measure and the order (asc or desc) to use as default order
|
||||
in the view.
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<pivot default_order="foo asc">
|
||||
<field name="foo" type="measure"/>
|
||||
</pivot>
|
||||
|
||||
The only allowed element within a pivot view is ``field`` which can have the
|
||||
following attributes:
|
||||
|
||||
Reference in New Issue
Block a user