htmlcssreactjsnext.jsreact-data-table-component

NextJS React-Data-Table-Component Styling


Task:

Issue:

Tried:

Details:

Needs solution:

Example Column:

    {
    name: 'header1',
    id: 'header1',
    maxWidth: 'auto',
    minWidth: 'auto',
    selector: row => row.data1,
    sortable: true,
    compact: true,
},

Example Table:

<div style={{ overflowX: "visible", scrollSnapAlign: "start" }}>
            <DataTable
                columns={DataTableHeaders}
                data={filteredItems}
                pagination
                paginationComponentOptions={paginationComponentOptions}
                selectableRows
                defaultSortField="name"
                subHeader
                subHeaderComponent={subHeaderComponent}
                subHeaderAlign={Alignment.CENTER}
                expandableRows
                expandableRowsComponent={ExpandedComponent}
                dense
                highlightOnHover
                fixedHeader
                persistTableHead
                responsive
                direction={Direction.LTR}
            //customStyles={customStyles}
            //theme="dark"
            //className={styleDataTable.rdt_TableRow}
            />
    </div>

Solution

  • Apparently this issue can be solved by setting fixed % width based on viewable area

            <div style={{ overflowX: "hidden", width: "94vw", alignItems: "flex-start" }}>
                <DataTable
                    className={styleDataTable.rdt_TableCol}
                    columns={DataTableHeaders}
                    data={filteredItems}
                    pagination
                    paginationComponentOptions={paginationComponentOptions}
                    defaultSortField="name"
                    subHeader
                    subHeaderComponent={subHeaderComponent}
                    subHeaderAlign={Alignment.LEFT}
                    expandableRows
                    expandableRowsComponent={ExpandedComponent}
                    dense
                    highlightOnHover
                    fixedHeader
                    persistTableHead
                    responsive
                    direction={Direction.LTR}
                //customStyles={customStyles}
                //theme="dark"
                //className={styleDataTable.rdt_TableRow}
                />
        </div>
    

    Notice that width: 94vw which will make the table fit on the 94% of the visible area. This way it becomes scrollable from left to right and the data table wont overflow and wont disappear.

    Not sure if there is a better solution but for now this works alright.