From dddaff8418c137a6c68e695ce7a971a2b02b9a1c Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 16 Aug 2019 11:08:00 +0000 Subject: [PATCH] [IMP] web: list: keep widths when removing last record When there were records in the list (and the browser computed the optimal column widths according to them), and the user removes them, we want to keep the widths as they are instead of forcing them according to the field's types. --- .../js/views/list/list_editable_renderer.js | 4 +-- .../relational_fields/field_one2many_tests.js | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index b3ee0e43fa4..020f91612ab 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -541,7 +541,7 @@ ListRenderer.include({ * @private */ _freezeColumnWidths: function () { - if (!this.state.data.length) { + if (!this.state.data.length && !this.columnWidths) { // there is no record -> don't force column's widths w.r.t. their label return; } @@ -913,7 +913,7 @@ ListRenderer.include({ _renderHeader: function () { var $thead = this._super.apply(this, arguments); - if (this.editable && !this.state.data.length) { + if (this.editable && !this.state.data.length && !this.columnWidths) { // we compute the sum of the weights for each columns, excluding // those with an absolute width. var totalWidth = this.columns.reduce(function (acc, column) { diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index e8d8785b77a..19883a53c73 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -8606,6 +8606,38 @@ QUnit.module('fields', {}, function () { form.destroy(); }); + + QUnit.test('column widths are kept when remove last record in o2m', async function (assert) { + assert.expect(1); + + this.data.partner.records[0].p = [2]; + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + var width = form.$('th[data-name="date"]')[0].offsetWidth; + + await testUtils.dom.click(form.$('.o_data_row .o_list_record_remove')); + + assert.strictEqual(form.$('th[data-name="date"]')[0].offsetWidth, width); + + form.destroy(); + }); }); }); });