Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 Respostas
Responde à pergunta

0

You should call it as function hide: hideColumn()

about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda