diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js index 9b154214dfc..2aa4cd93797 100644 --- a/addons/web/static/src/js/views/pivot/pivot_controller.js +++ b/addons/web/static/src/js/views/pivot/pivot_controller.js @@ -344,7 +344,7 @@ var PivotController = AbstractController.extend({ var isAscending = $target.hasClass('o_pivot_measure_row_sorted_asc'); this.model .sortRows(this.handle, col_id, measure, isAscending) - .then(this.update_state.bind(this)); + .then(this.update.bind(this, {}, {reload: false})); }, /** * This method is called when someone clicks on an open header. When that diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js index ff0b80dd103..d2bf632053c 100644 --- a/addons/web/static/src/js/views/pivot/pivot_model.js +++ b/addons/web/static/src/js/views/pivot/pivot_model.js @@ -284,21 +284,20 @@ var PivotModel = AbstractModel.extend({ * @returns {Deferred} */ sortRows: function (id, col_id, measure, descending) { - var record = this.localData[id]; - - _traverseTree(record.data.main_row.root, function (header) { + var cells = this.data.cells; + this._traverseTree(this.data.main_row.root, function (header) { header.children.sort(compare); }); - record.sorted_column = { + this.data.sorted_column = { id: col_id, measure: measure, order: descending ? 'desc' : 'asc', }; function _getValue (id1, id2) { - if ((id1 in record.data.cells) && (id2 in record.data.cells[id1])) { - return record.data.cells[id1][id2]; + if ((id1 in cells) && (id2 in cells[id1])) { + return cells[id1][id2]; } - if (id2 in record.data.cells) return record.data.cells[id2][id1]; + if (id2 in cells) return cells[id2][id1]; } function compare (row1, row2) { diff --git a/addons/web/static/test/views/pivot_tests.js b/addons/web/static/test/views/pivot_tests.js index bed3294cfe9..def0896abce 100644 --- a/addons/web/static/test/views/pivot_tests.js +++ b/addons/web/static/test/views/pivot_tests.js @@ -452,4 +452,33 @@ QUnit.module('Views', { pivot.destroy(); }); + QUnit.test('can sort data in a column by clicking on header', function (assert) { + assert.expect(3); + + var pivot = createView({ + View: PivotView, + model: "partner", + data: this.data, + arch: '' + + '' + + '' + + '', + }); + + assert.strictEqual($('td.o_pivot_cell_value').text(), "321220", + "should have proper values in cells (total, result 1, result 2"); + + pivot.$('th.o_pivot_measure_row').click(); + + assert.strictEqual($('td.o_pivot_cell_value').text(), "322012", + "should have proper values in cells (total, result 2, result 1"); + + pivot.$('th.o_pivot_measure_row').click(); + + assert.strictEqual($('td.o_pivot_cell_value').text(), "321220", + "should have proper values in cells (total, result 1, result 2"); + + pivot.destroy(); + }); + });});