Search code examples
odooodoo-11

how to hide or remove checkbox column by default on tree view?


When creating a tree view by default, one more column appears with a checkbox

Something like thate

how to hide or remove this column?

I will appreciate all your help.


Solution

  • The selector is added in list renderer _renderSelector function, which is called when rendering the header or a row.
    Odoo checks if the list renderer hasSelectors attribute is set to true to add the selector (checkbox). To disable the selector, you will need to set hasSelectors to false when initializing the widget.

    You can easily override the init function to be able to deactivate the selector by passing a value in the action context.

    The following example alters the init function of the form render to check if hasSelectors attribute is present in state context and its value is set to false:

    var ListRenderer = require('web.ListRenderer');
    ListRenderer.include({
        init: function (parent, state, params) {
            this._super(parent, state, params);
            if ('hasSelectors' in state.context && !state.context.hasSelectors)
                this.hasSelectors = false;
        },
    });
    

    Using the above example, you can disable the selectors in any tree view just by setting the value of hasSelectors to False in context.