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

142
Vistas
Antdesign table not rerendering on new column values

I am having trouble rerendering the columns of my table, the library i am using is ant design and I am trying to create a feature where I reorder the column of the table on demand.

I have created an example the issue here: https://replit.com/@coupacoupa/Ant-Design-column-reordering

In the example, I created a simple button that changes the order of the column which changes a div showcasing the state changed, but in the ant design table, the column doesn't change.

Below is a snipplet of the way I change the state

export default ({ columnOrder, data }: IProps) => {
  const [orderedColumn, setOrderedColumn] = useState<ColumnsType<ISomeTableColumns>>(columns);

  useEffect(() => {
    console.log('columnOrder', columnOrder);
    const sortArray = columns.sort((a, b) => {
      return (
        columnOrder.findIndex((x) => x.text === a.title) -
        columnOrder.findIndex((x) => x.text === b.title)
      );
    });

    if (sortArray) {
      setOrderedColumn(sortArray);
    }
  }, [columnOrder]);

  return <>
    <Table
      columns={orderedColumn}
      dataSource={data}
      bordered
      size="middle"
      scroll={{ x: 'calc(700px + 50%)' }}
    />
    <h2>Value Of ordered Columns</h2>
    <div>{JSON.stringify(orderedColumn)}</div>
  </>
};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The sort() method sorts the elements of an array in place and returns the reference to the same array, now sorted. But you should pass a new array into setOrderedColumn to rerender

  useEffect(() => {
    console.log('columnOrder', columnOrder);
    columns.sort((a, b) => {
      return (
        columnOrder.findIndex((x) => x.text === a.title) -
        columnOrder.findIndex((x) => x.text === b.title)
      );
    });

    if (columns) {
      setOrderedColumn([...columns]);
    }
  }, [columnOrder, columns]);
about 4 years ago · Juan Pablo Isaza Denunciar
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