Skip to content Skip to sidebar Skip to footer

React Ant Table Customized Column Calculation. How To Get The Length Of Other Items In Each Row

I made an application where I output the length of the questions for each post, but I get the result for each post equal with: 310. Probably it happens because of too many render

Solution 1:

Fix the incorrect number: do not push, use callback event of render instead

Ant Table API: table Column

const App = () => {
  const res = [
    ...Object.keys(posts[0]).map(i => {
      return {
        title: i,
        dataIndex: i,
        key: i
      };
    }),
    {
      title: "Questions",
      key: "Questions",
      render: e => {
        console.log(e); // Object {title: 1, id: "123"}
        return (
          <Router>
            <Link to={`demo/${e.id}/url`}>
              {questions.filter(q => q.id_post.toString() === e.id).length}
            </Link>
          </Router>
        );
      }
    }
  ];
  return <Table columns={res} dataSource={posts} />;
};

enter image description here

Edit Basic Usage - Ant Design Demo


Post a Comment for "React Ant Table Customized Column Calculation. How To Get The Length Of Other Items In Each Row"