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

142
Views
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
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!