[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.
This commit is contained in:
Aaron Bohy
2019-08-23 06:28:35 +00:00
parent 1824020cc2
commit dddaff8418
2 changed files with 34 additions and 2 deletions
@@ -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) {
@@ -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: '<form>' +
'<field name="p">' +
'<tree editable="top">' +
'<field name="date"/>' +
'<field name="foo"/>' +
'</tree>' +
'</field>' +
'</form>',
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();
});
});
});
});