react-component / react-component/table

Header scrollLeft set to 0 when adding a new column

Open
#699 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.4k
Forks
618
Avg merge
10h 19m
Merged PRs (30d)
2

Description

code:
import React from 'react';
import Table from 'rc-table';
import '../../assets/index.less';

const columns = [
  { title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
  { title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
  { title: 'title3', dataIndex: 'c', key: 'c', width: 100 },
  { title: 'title4', dataIndex: 'b', key: 'd', width: 100 },
  { title: 'title5', dataIndex: 'b', key: 'e', width: 100 },
  { title: 'title6', dataIndex: 'b', key: 'f', width: 100 },
  { title: 'title7', dataIndex: 'b', key: 'g', width: 100 },
  { title: 'title8', dataIndex: 'b', key: 'h', width: 100 },
  { title: 'title9', dataIndex: 'b', key: 'i', width: 100 },
  { title: 'title10', dataIndex: 'b', key: 'j', width: 100 },
  { title: 'title11', dataIndex: 'b', key: 'k', width: 100 },
  { title: 'title12', dataIndex: 'b', key: 'l', width: 100 },
];

const data = [
  { a: '123', b: 'xxxxxxxx xxxxxxxx', d: 3, key: '1' },
  { a: 'cdd', b: 'edd12221 edd12221', d: 3, key: '2' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '3' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '4' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '5' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '6' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '7' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '8' },
  { a: '133', c: 'edd12221 edd12221', d: 2, key: '9' },
];

const Demo = () => {
  const [visible, setVisible] = React.useState(true);
  const [cols,setCols] = React.useState(columns);
  return (
    <div>
      <h2>Scroll X/Y</h2>
      <button
        type="button"
        onClick={() => {
          setVisible(!visible);
        }}
      >
        Trigger Visible
      </button>
      <button type='button' onClick={()=>{
        setCols((cols)=>{
          const newCols = [...cols];
          newCols.push({ title: `titleN`, dataIndex: 'b', key: `N`, width: 100 });
          return newCols;
        })
      }}>
        add column
      </button>
      <div style={{ display: visible ? undefined : 'none' }}>
        <Table
          useFixedHeader
          style={{ width: 800 }}
          scroll={{ x: 1500, y: 300 }}
          columns={cols}
          data={data}
        />
      </div>
    </div>
  );
};

export default Demo;
performance

https://user-images.githubusercontent.com/59195554/142131119-39a2e9de-a394-4083-b2a2-1edd70c02d3a.mov

expect

header and body remain the same position when adding a column

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Demo reproduction using the Table component, horizontal scrolling, and the add-column action. Trace how the header and body scroll positions are handled when the columns change, then verify that adding a column leaves both positions unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.