How to make Datagrid2 Selector-column take up no space.

0
In DataGrid2, the selector column is in the datagrid at the right side taking up space, several 10s of pixels, that is therefor empty space.This is space that is very much needed for the datagrids actual dataIt makes the datagrid's right side look strange, and misalignedHow take make:the column disappearthe eye-button locate somewhere else, the datagrid header perhaps.
asked
2 answers
0

You can achieve this in 2 manners:

  1. combining the last 2 columns with each other and not displaying the last one (display none)

  2. setting padding & width to zero for the last column and expanding the total datagrid width to account for the width loss of not showing the last column

Additionally, you can float the eye-button with a 'position absolute'

Each has pros and cons

Code for the first one can be:

.dg2-floating-eye {
    .widget-datagrid-content {
        position: relative;
    }

    .widget-datagrid-grid-head .tr .th.column-selector {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 10;
        background: transparent;
        border: none;
    }

    .widget-datagrid-grid-body .tr .td:last-child {
        display: none;
    }

    .widget-datagrid-grid-head .tr .th:nth-last-child(2),
    .widget-datagrid-grid-body .tr .td:nth-last-child(2) {
        grid-column: span 2;
    }
}

pros: true 100% width, right-side borders & hor-scrolling work properly; no hardcoding pixel calculations for the last-column-width

Second option/method:

.dg2-floating-eye {
    .widget-datagrid-content {
        position: relative;
        overflow-x: hidden;
    }

    .widget-datagrid-grid.table {
        width: calc(100% + 54px);
    }

    .widget-datagrid-grid-head .tr .th.column-selector {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 10;
        background: transparent;
        border: none;
    }

    .widget-datagrid-grid-body .tr .td:last-child {
        width: 0;
        padding: 0;
        border: 0;
    }
}

answered
0

Hi Tim,

The space on the right is reserved for Data Grid 2's built-in column selector (the eye icon), which is rendered when column hiding is enabled.

There are two different approaches depending on whether you want to retain column personalization.

Option 1 — Remove the selector completely (supported configuration)

If you don't need column hiding:

  1. Open the Data Grid 2 properties.

  2. Go to Personalization → Column Capabilities.

  3. Set Hiding = No.

This disables the column selector functionality and removes the need for the eye icon.

Option 2 — Keep the eye icon without reserving a separate grid column

If you want to retain column hiding, you can use a scoped CSS override to reposition the existing selector over the grid header instead of allocating additional horizontal space.

The important distinction is that hiding the button with display: none is not sufficient, because the grid's layout may still reserve space for the selector.

I would approach it as follows:

  1. Assign a custom class to the Data Grid 2, for example compact-column-selector.

  2. Inspect the rendered grid in browser DevTools and identify the selector's header cell, the eye button, and the layout rule reserving its width.

  3. Override the selector cell's layout so it no longer contributes a separate grid track.

  4. Position the existing eye button absolutely within a positioned header container.

  5. Reserve sufficient space inside the last visible column header to prevent overlap with its caption, sorting, or filter controls.

For example, the positioning concept is:

.compact-column-selector {
    // Apply these rules to the actual selector elements
    // identified in DevTools for your Data Widgets version.

    .selector-header-container {
        position: relative;
    }

    .selector-button {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 2;
    }
}

The selectors above are illustrative placeholders, not actual Data Grid 2 class names. The exact implementation must target the rendered DOM structure and remove the reserved layout track as well as reposition the button.

Important: This is a CSS customization, not a supported Data Grid 2 configuration. It should be tested after Data Widgets upgrades, particularly with horizontal scrolling, column resizing, sticky columns, and responsive layouts.

There is currently no documented Data Grid 2 property to move the built-in column selector into an external toolbar or header while retaining its native behavior.

Official documentation:
https://docs.mendix.com/appstore/modules/data-grid-2-properties/

Hope this helps! If you find this answer helpful, please mark it as the accepted answer.

answered