Antd Table: autosize scroll:y to parent

Viewed 286

I'm using Antd table and I'm using scroll: {y:...} to have the table contents scrollable. I'd like to have the table auto-size to fit the parent and be responsive to re-sizes. ('auto' sizes the control to fit all its contents, which is not what I need.) Currently I'm just hacking a constant height that works when the app is maximized on my primary monitor. I've tried several CSS overrides, but I can't seem to get this to work as desired.

1 Answers
import { Table } from 'antd';

const columns = [
  {
    title: 'Name (all screens)',
    dataIndex: 'name',
    key: 'name',
    render: text => <a>{text}</a>,
  },
  {
    title: 'Age (medium screen or bigger)',
    dataIndex: 'age',
    key: 'age',
    responsive: ['md'],
  },
  {
    title: 'Address (large screen or bigger)',
    dataIndex: 'address',
    key: 'address',
    responsive: ['lg'],
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
  },
];

ReactDOM.render(<Table columns={columns} dataSource={data} />, mountNode);

You can take inspiration from the above example

Related