Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
How to hide a column on Material UI based on certain criteria?

I have a datagrid using MUI and I have came across a use case where I need to hide one of the columns if I do not have a certain role. Here is the code.

const hideColumn = () => {
        const globalAdmin = auth.verifyRole(Roles.Admin);

        if(!globalAdmin){
            return true;
        }
        return false;
    };


const columns = [
        { field: 'id', headerName: 'ID', width: 100 },
        { field: 'name',
          headerName: 'Client code',
          flex: 1,
          hide: hideColumn,
          renderCell: (params) => {
                    
                    return params.getValue("name");
            },
        },
];

I'm confused on why this is not working. If I just use hide:true or hide:false it works but I need have an if statement to check the credentials first and this can't be done in the renderCell (or at least I can't get it to work). Does anyone know how to do this correctly?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You should call it as function hide: hideColumn()

about 4 years ago · Juan Pablo Isaza Report

0

Or you can create a function to retrieve your columns and pass props to this function. Then you just have to push your columns according to criteria:

export default function getColumns (product, isHide, t) {
let columns = [
    {
      field: 'organizationName',
      headerName: headerNameOrganization,
      flex: 0.3,
    },
 ]
  if (!product) {
    columns.push(
      {
        field: 'status',
        headerName: headerNameStatus,
        flex: 0.2,
        filterable: false,
  })
}
return columns
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!