diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index e43817143c0..bc84978c380 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -66,9 +66,7 @@ export class ListRenderer extends Component { this.cellClassByColumn = {}; this.groupByButtons = this.props.archInfo.groupBy.buttons; this.state = useState({ - columns: this.allColumns.filter( - (col) => !col.optional || this.optionalActiveFields[col.name] - ), + columns: this.getActiveColumns(this.props.list), }); this.withHandleColumn = this.state.columns.some((col) => col.widget === "handle"); useExternalListener(document, "click", this.onGlobalClick.bind(this)); @@ -92,9 +90,7 @@ export class ListRenderer extends Component { }); onWillUpdateProps((nextProps) => { this.allColumns = nextProps.archInfo.columns; - this.state.columns = this.allColumns.filter( - (col) => !col.optional || this.optionalActiveFields[col.name] - ); + this.state.columns = this.getActiveColumns(nextProps.list); }); onPatched(() => { const editedRecord = this.props.list.editedRecord; @@ -189,6 +185,15 @@ export class ListRenderer extends Component { }); } + getActiveColumns(list) { + return this.allColumns.filter((col) => { + if (list.isGrouped && col.widget === "handle") { + return false; // no handle column if the list is grouped + } + return !col.optional || this.optionalActiveFields[col.name]; + }); + } + get hasSelectors() { return this.props.allowSelectors && !this.env.isSmall; } @@ -1560,9 +1565,7 @@ export class ListRenderer extends Component { async toggleOptionalField(fieldName) { await this.props.list.unselectRecord(true); this.optionalActiveFields[fieldName] = !this.optionalActiveFields[fieldName]; - this.state.columns = this.allColumns.filter( - (col) => !col.optional || this.optionalActiveFields[col.name] - ); + this.state.columns = this.getActiveColumns(this.props.list); this.saveOptionalActiveFields( this.allColumns.filter((col) => this.optionalActiveFields[col.name] && col.optional) ); diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 9a6e4dea8fa..2d42736c3b9 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -1233,15 +1233,15 @@ QUnit.module("Views", (hooks) => { groupBy: ["bar"], }); - assert.strictEqual($(target).find("th:contains(Foo)").length, 1, "should contain Foo"); - assert.strictEqual($(target).find("th:contains(Bar)").length, 1, "should contain Bar"); - assert.containsN(target, "tr.o_group_header", 2, "should have 2 .o_group_header"); - assert.containsN(target, "th.o_group_name", 2, "should have 2 .o_group_name"); - assert.containsNone( - target, - "th:contains(int_field)", - "Should not have int_field in grouped list" - ); + assert.containsN(target, "thead th", 3); // record selector + Foo + Bar + assert.containsOnce(target, "thead th.o_list_record_selector"); + assert.containsOnce(target, "thead th[data-name=foo]"); + assert.containsOnce(target, "thead th[data-name=bar]"); + assert.containsNone(target, "thead th[data-name=int_field]"); + assert.containsN(target, "tr.o_group_header", 2); + assert.containsN(target, "th.o_group_name", 2); + assert.containsN(target.querySelector(".o_group_header"), "th", 2); // group name + colspan 2 + assert.containsNone(target.querySelector(".o_group_header"), ".o_list_number"); }); QUnit.test("basic grouped list rendering 1 col without selector", async function (assert) {