Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
React Material-Table: difficulties with getting value from a filterComponent or passing a function to filterComponent

I'm using Material-Table in a React app. I enabled filtering, and after, I used Material-Table's filterComponent.

I have problems with retrieving the value from Column1FilterComponent custom component or pass down a function which can trigger a state change, and after it could trigger a fetch. I placed my setFetchState(...) function to the point I'd like it to be. Here is an example: https://codesandbox.io/s/material-table-playground-forked-simple-q05vhf

Here are my questions: How to get value from a filterComponent? How to pass a function to filterComponent?

export function SomethingTable(props) {
  const { fetchState, setFetchState } = props;
  const [randomData, setRandomData] = useState([
    { filename: "1", another: "two" },
    { filename: "2", another: "three" },
    { filename: "3", another: "four" },
    { filename: "4", another: "five" },
    { filename: "5", another: "six"
    }
  ]);

  return (
    <MaterialTable
      title="Something"
      columns={[
        {
          title: "Column1",
          field: "filename",
          type: "numeric",
          width: "10%",
          filterComponent: (props) => <Column1FilterComponent {...props} />
        },
        { title: "Column2", field: "another" }
      ]}
      data={randomData}
      /*onFilterChange={(filters) => {
          console.log("filters", filters);
        }}*/
      options={{
        filtering: true
      }}
    />
  );
}

function Column1FilterComponent(props) {
  const [value, setValue] = useState("");
  return (
    <TextField
      id="area-text"
      value={value}
      onChange={(event) => {
        setValue(event.target.value);
        //My set function:
        // setFetchState(event.target.value);
        props.onFilterChanged(props.columnDef.tableData.id, event.target.value);
      }}
    />
  );
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda