在 Protable 中,可以使用 `columnWidth` 属性来设置每一列的宽度。`columnWidth` 属性接受一个数组,数组中的每个元素对应表格中每一列的宽度。\n\n例如,如果想要设置第一列的宽度为 100px,第二列的宽度为 200px,可以这样写:\n\njavascript\nconst columns = [\n { title: \'列1\', dataIndex: \'col1\', key: \'col1\', width: 100 },\n { title: \'列2\', dataIndex: \'col2\', key: \'col2\', width: 200 },\n];\n\nconst data = [\n { col1: \'数据1\', col2: \'数据2\' },\n { col1: \'数据3\', col2: \'数据4\' },\n];\n\n<Table columns={columns} dataSource={data} />\n\n\n如果想要设置每一列的宽度为相同的值,可以使用 `fixed` 属性来固定列宽,然后使用 `width` 属性来设置宽度值。\n\njavascript\nconst columns = [\n { title: \'列1\', dataIndex: \'col1\', key: \'col1\', width: 100, fixed: \'left\' },\n { title: \'列2\', dataIndex: \'col2\', key: \'col2\', width: 100 },\n { title: \'列3\', dataIndex: \'col3\', key: \'col3\', width: 100 },\n // ...更多列\n];\n\nconst data = [\n { col1: \'数据1\', col2: \'数据2\', col3: \'数据3\' },\n { col1: \'数据4\', col2: \'数据5\', col3: \'数据6\' },\n // ...更多数据\n];\n\n<Table columns={columns} dataSource={data} scroll={{ x: 300 }} />\n\n\n在上面的例子中,第一列的宽度固定为 100px,其他列的宽度也会自动调整为 100px,如果表格的宽度超过 300px,会出现横向滚动条。

Protable 表格列宽设置:灵活调整和固定列宽

原文地址: https://www.cveoy.top/t/topic/pyx4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录