diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap index 58b620d75..e3229ca39 100644 --- a/components/table/__tests__/__snapshots__/demo.test.js.snap +++ b/components/table/__tests__/__snapshots__/demo.test.js.snap @@ -1023,7 +1023,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns.md correctly 1`] = `
- +
@@ -1054,7 +1054,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns.md correctly 1`] = `
-
+
@@ -1291,7 +1291,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns-header.md correctly
-
+
@@ -1308,7 +1308,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns-header.md correctly
-
+
@@ -1361,7 +1361,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns-header.md correctly
-
+
@@ -1375,7 +1375,7 @@ exports[`renders ./antdv-demo/docs/table/demo/fixed-columns-header.md correctly
-
+
@@ -1919,7 +1919,7 @@ exports[`renders ./antdv-demo/docs/table/demo/grouping-columns.md correctly 1`]
-
+
@@ -1935,7 +1935,7 @@ exports[`renders ./antdv-demo/docs/table/demo/grouping-columns.md correctly 1`]
-
+
@@ -1977,7 +1977,7 @@ exports[`renders ./antdv-demo/docs/table/demo/grouping-columns.md correctly 1`]
-
+
@@ -1991,7 +1991,7 @@ exports[`renders ./antdv-demo/docs/table/demo/grouping-columns.md correctly 1`]
-
+
diff --git a/components/table/__tests__/__snapshots__/empty.test.js.snap b/components/table/__tests__/__snapshots__/empty.test.js.snap index 4a92bb528..e4341ca2e 100644 --- a/components/table/__tests__/__snapshots__/empty.test.js.snap +++ b/components/table/__tests__/__snapshots__/empty.test.js.snap @@ -176,7 +176,7 @@ exports[`Table renders empty table with fixed columns 1`] = `
-
+
@@ -198,7 +198,7 @@ exports[`Table renders empty table with fixed columns 1`] = `
-
+
diff --git a/components/vc-table/src/BaseTable.jsx b/components/vc-table/src/BaseTable.jsx index fe152d1de..0a63b02a6 100644 --- a/components/vc-table/src/BaseTable.jsx +++ b/components/vc-table/src/BaseTable.jsx @@ -146,7 +146,7 @@ const BaseTable = { render() { const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table; const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props; - + const columns = this.getColumns(); const tableStyle = {}; if (!fixed && scroll.x) { @@ -158,6 +158,14 @@ const BaseTable = { tableStyle.width = typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width; } + if(fixed) { + const width = columns.reduce((sum, {width: w})=>{ + return sum + parseFloat(w, 10); + }, 0); + if(width > 0) { + tableStyle.width = width + 'px'; + } + } const Table = hasBody ? components.table : 'table'; const BodyWrapper = components.body.wrapper; @@ -169,7 +177,6 @@ const BaseTable = { body = getBodyWrapper(body); } } - const columns = this.getColumns(); return (