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 9275d414578..093b419b18d 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 @@ -566,19 +566,21 @@ ListRenderer.include({ // width. return 1; } - var widget = this.state.fieldsInfo.list[column.attrs.name].Widget.prototype; - if ('widthFactor' in widget) { - return widget.widthFactor; - } - switch (field.type) { - case 'boolean': return '40px'; - case 'date': return '92px'; - case 'datetime': return '146px'; - case 'float': return '92px'; - case 'integer': return '74px'; - case 'monetary': return '104px'; - default: return 1; // evenly distribute the remaining space + var widgetProto = this.state.fieldsInfo.list[column.attrs.name].Widget.prototype; + if ('widthFactor' in widgetProto) { + return widgetProto.widthFactor; } + var fixedWidthTypes = { + boolean: '40px', + date: '92px', + datetime: '146px', + float: '92px', + integer: '74px', + monetary: '104px', + }; + var widget = this.state.fieldsInfo.list[column.attrs.name].widget; + var type = widget in fixedWidthTypes ? widget : field.type; + return fixedWidthTypes[type] || 1; }, /** * diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 8397364dd2f..66629defcb3 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -1497,6 +1497,26 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('column width should depend on the widget', async function (assert) { + assert.expect(1); + + this.data.foo.records = []; // the width heuristic only applies when there are no records + var list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '' + + '' + + '' + + '', + }); + + assert.strictEqual(list.$('th[data-name="datetime"]')[0].offsetWidth, 92, + "should be the optimal width to display a date, not a datetime"); + + list.destroy(); + }); + QUnit.test('row height should not change when switching mode', async function (assert) { // Warning: this test is css dependant assert.expect(3);