Statically positioned column in PrimeReact's datatable achieved without utilizing jQuery

I have been looking into ways to make one of the columns in my datatable fixed. While I came across a solution using jQuery, I am interested in achieving this without relying on jQuery. Are there any tips you could offer on how to achieve this using HTML, CSS, or just vanilla JavaScript?

Below is the CSS code for my table:

#invoiceTable {
    margin-top: 1.2rem;
    margin: 5px;
    
    .p-datatable-wrapper {
        overflow: auto;
        height: auto;
        border-bottom: 1px solid #e9ecef;

        .p-datatable-thead {
            tr {
                th:nth-child(27) {
                    display: flex;
                    flex-direction: row;
                    position: fixed;
                }
            }
        }

    .p-paginator {
        padding: 0;
        display: flex;
        justify-content: start;

        .p-paginator-left-content {
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
    }
}

The column I want to make fixed is nth-child(27), which happens to be the last column.

Your help will be greatly appreciated.

Answer №1

To utilize the prime react datatable effectively, you must ensure that the datatable is set as scrollable and the column as frozen. Here's an example:

<DataTable value={products} responsiveLayout="scroll" scrollable>
      ... Other columns
      <Column
        field="category"
        header="Category frozen"
        frozen
        alignFrozen="right"
      ></Column>
    </DataTable>

Check out this sandbox showcasing the frozen column: https://codesandbox.io/s/charming-sun-6lnd1w

UPDATE: I have made some changes to the sandbox by incorporating autoLayout and removing responsiveLayout, while still maintaining the functionality. https://codesandbox.io/s/damp-voice-38mjwu

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Examining React components with Enzyme for event usage in components

Struggling with testing react components that utilize event.target in events has been a challenge for me. Take for example the component code snippet below; import * as React from 'react'; import { generateGuid } from '../../../utilities/Gu ...

React: Material UI, Counting All the Rows

How many rows does Material UI in REACT support in its free and paid versions? I have a massive dataset exceeding 400 MB. Is this realistic or too ambitious? ...

In Laravel Blade, you can dynamically add rows and columns based on a certain condition

I'm working on creating a user interface for cinema seats in Laravel Blade. The database includes seat rows and columns, and the rows will be the same for two consecutive rows. For example, the first row could have an id of 1 with seat_row:1 and seat_ ...

How come I am unable to retrieve it as an object (abonnes) using the GetElementById method from the result?

Why am I not able to retrieve 'abonnes' as an object from the result of GetElementById? The element is available in JSON format. function Abonnes() { const [abonnes, setAbonnes] = useState(); const getOneAbonnes = (id) => { Axios.get( ...

Obtain data with matching JSON values in a REACT application

Recently, I received a JSON file that looks something like this: [ { "symbol": "A", "name": "Agilent Technologies Inc", "exchange": "NYSE", }, { "symbol": "AAC ...

What is the best way to add a new row div for every third item in props?

I have created a series of dashboards that are displayed in bootstrap cards on the main page. I am looking to group them together by wrapping every third dashboard in a div with the class row. Initially, I considered using the dashboard component's ID ...

A guide on detecting overflow in a React functional component

I am in search of a way to determine if a div contains overflowing text and display a "show more" link if it does. While researching, I came across an insightful Stack Overflow answer on checking for overflow in a div. The answer suggests implementing a fu ...

Implementing Material UI datetime-local feature with no minute selection

Is there a way to hide minutes in a TextField with type = datetime-local? <TextField label="From" type="datetime-local" InputLabelProps={{ shrink: true, }} /> This is how it appears on my end: screenshot ...

Displaying a relative div on mouse hover over an HTML tag using React

In the section below, you will find the code snippet... <ul className="no-style board__list"> {Object.keys(today.books).map(function(id) { var refBook = today.books[id][0]; return ( ...

Stop rows from causing the table to stretch in width

We have a unique table structure where the first row contains two cells and the second row contains only one cell. The width of each cell is determined by its content. Our goal is to prevent the cell in the second row from expanding the overall table widt ...

React-Router's Seamless Deep Sub-Route Redirect Functionality

Lately, I've been in the process of migrating a project from AngularJS + UI-Router + UI-Router-Extras to React + React-Router. A standout feature in UI-Router-Extras that caught my eye and I'd like to incorporate into React-Router is called De ...

How can I adjust the border opacity in a React application?

Can we adjust the border color opacity in React when using a theme color that is imported? For example, if our CSS includes: borderBottomColor: theme.palette.primary.main and we are importing the theme with Material UI using makeStyles, is there a way to ...

Keep Variable-Height Element Corners Rounded to Perfection

I am facing a challenge with creating buttons that have perfectly rounded corners. The button is 50px high and the border radius is set to 25px, resulting in a perfect half-circle on each side of the button: It's pretty straightforward to achieve thi ...

CSS confusion: What's causing the header to not align horizontally and the footer to not justify evenly spaced?

I am new to coding and experimenting with CSS flexbox to design a responsive layout. I am struggling with aligning the header elements horizontally in the widest viewport and adjusting the footer to space out evenly. For the header, I attempted using disp ...

Achieving consistent alignment of items on smaller screen sizes using Bootstrap

I'm facing some challenges while creating a website using Bootstrap. I've encountered an issue where the columns in a row stack on top of each other when the screen size is reduced. Here is my current code: <div class="row"> <d ...

Maintaining a sticky footer that remains visible throughout the content as the screen is resized

For more information, please visit my website at I attempted to implement a "sticky footer" technique following the steps outlined in this tutorial (http://ryanfait.com/sticky-footer/) Unfortunately, the sticky footer does not function properly when resi ...

Challenges with accessibility when implementing Material-UI 'Menu' over a 'Drawer' component

I encountered an issue with accessibility while working with Material-UI and React. The problem arose when I tried placing a Menu within a Drawer component. Typically, a Menu highlights the top MenuItem by default. However, this behavior changes when the M ...

Create a dynamic list of checkboxes populated by API data and utilize React hooks to handle updates

I am looking to utilize hooks within my component that generates a list of checkboxes and allows for independent status updates for each checkbox. To accomplish this, I am currently utilizing useSelector() to retrieve the checkbox data obtained from the U ...

Issues with footers in IE 10/11 and Edge when using Grid layout

In the latest versions of Chrome, Firefox, Opera, IE 10/11 and Edge, the Grid layout below works perfectly fine. The only issue is with the Microsoft browsers where the footer fails to start scrolling when the content exceeds the screen size, leaving it fi ...

Incorporating the names of countries onto a map using React Maps

I have a map that I would like to use. You can find it at this link: However, the issue is that users need to hover over the geographies to see the country names. I want the country names to be displayed directly on the geographies. ...