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

149
Vistas
Custom sort method for react table header

I need to sort a react-table based on different values depending on the column header that is clicked. So far this is my code:

{
    sortMethod: (a: ListItem, b: ListItem) => {
      console.log(a, b);
      return 1;
    },
    Header: (rest) => {
      console.log(rest);
      return (
        <Flex height={16} width="100%" justifyContent="center">
          <Text onClick={() => rest.column.sortMethod()} color="black">Name</Text>
        </Flex>
      );
    },
    accessor: 'product.name',
    minWidth: 280,
  },

This being my table:

<Table
      key={`table.${products.length}.${selectedKeys.join('.')}`}
      isSelectable
      showPagination={showPagination}
      defaultPageSize={defaultPageSize}
      pageSizeOptions={pageSizes}
      onSelectionChange={(newSelectedProducts: ListItem[]) => {
        if (tableProductsWithTags.length > 0) {
          setSelectedProducts(newSelectedProducts.filter(Boolean));
        }
      }}
      noDataText={isLoading ? 'Loading ...' : 'No products'}
      columns={projectColumns}
      selectedKeys={selectedKeys}
      keyField="id"
      defaultSorted={sortingOptions}
      data={tableProductsWithTags}
      getTrProps={() => {
        return { style: { alignItems: 'start' }, passthrought: { onClick: setFilterOption } };
      }}
      getTdProps={
        ((_state, _rowInfo, column: { id: string }) => {
          const tdProps: { [key: string]: any } = {
            style: { minHeight: 55 }
          };
          if (column.id === 'tags') {
            tdProps.passthrough = { onEdit: handleEditProduct };
          }
          return tdProps;
        }) as ComponentPropsGetterRC
      }
      {...props}
    />

Passing a sort into the sortMethod prop seems like the correct way but how do I actually implement this? In the table you can see I pass in an onEdit method that handles when a cell is edited. I tried this way for a header as well but it seems like it does not have access to the same props.

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