Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
3499c9e6
Commit
3499c9e6
authored
Jan 16, 2026
by
hongjunpeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新2.15.12的table源码
parent
9b61ca0b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
86 deletions
+37
-86
package.json
package.json
+1
-1
packages/table/src/store/index.js
packages/table/src/store/index.js
+0
-6
packages/table/src/table-body.js
packages/table/src/table-body.js
+11
-35
packages/table/src/table-layout.js
packages/table/src/table-layout.js
+7
-39
packages/table/src/table.vue
packages/table/src/table.vue
+18
-5
No files found.
package.json
View file @
3499c9e6
{
{
"name"
:
"element-ui"
,
"name"
:
"element-ui"
,
"version"
:
"2.15.769
2
"
,
"version"
:
"2.15.769
3
"
,
"description"
:
"A Component Library for Vue.js."
,
"description"
:
"A Component Library for Vue.js."
,
"main"
:
"lib/element-ui.common.js"
,
"main"
:
"lib/element-ui.common.js"
,
"files"
:
[
"files"
:
[
...
...
packages/table/src/store/index.js
View file @
3499c9e6
...
@@ -98,7 +98,6 @@ Watcher.prototype.mutations = {
...
@@ -98,7 +98,6 @@ Watcher.prototype.mutations = {
}
}
this
.
updateTableScrollY
();
this
.
updateTableScrollY
();
this
.
syncFixedTableRowHeight
();
},
},
filterChange
(
states
,
options
)
{
filterChange
(
states
,
options
)
{
...
@@ -112,7 +111,6 @@ Watcher.prototype.mutations = {
...
@@ -112,7 +111,6 @@ Watcher.prototype.mutations = {
}
}
this
.
updateTableScrollY
();
this
.
updateTableScrollY
();
this
.
syncFixedTableRowHeight
();
},
},
toggleAllSelection
()
{
toggleAllSelection
()
{
...
@@ -146,8 +144,4 @@ Watcher.prototype.updateTableScrollY = function() {
...
@@ -146,8 +144,4 @@ Watcher.prototype.updateTableScrollY = function() {
Vue
.
nextTick
(
this
.
table
.
updateScrollY
);
Vue
.
nextTick
(
this
.
table
.
updateScrollY
);
};
};
Watcher
.
prototype
.
syncFixedTableRowHeight
=
function
()
{
Vue
.
nextTick
(()
=>
this
.
table
.
layout
.
syncFixedTableRowHeight
());
};
export
default
Watcher
;
export
default
Watcher
;
packages/table/src/table-body.js
View file @
3499c9e6
...
@@ -41,22 +41,13 @@ export default {
...
@@ -41,22 +41,13 @@ export default {
border
=
"
0
"
>
border
=
"
0
"
>
<
colgroup
>
<
colgroup
>
{
{
this
.
columns
this
.
columns
.
map
(
column
=>
<
col
name
=
{
column
.
id
}
key
=
{
column
.
id
}
/>
)
.
filter
((
column
,
index
)
=>
!
(
this
.
columnsHidden
[
index
]
&&
this
.
fixed
))
.
map
(
column
=>
<
col
name
=
{
column
.
id
}
key
=
{
column
.
id
}
/>
)
}
}
<
/colgroup
>
<
/colgroup
>
<
tbody
>
<
tbody
>
{
{
data
.
reduce
((
acc
,
row
)
=>
{
data
.
reduce
((
acc
,
row
)
=>
{
const
isSelected
=
this
.
store
.
isSelected
(
row
);
return
acc
.
concat
(
this
.
wrappedRowRender
(
row
,
acc
.
length
));
const
isExpanded
=
this
.
store
.
states
.
expandRows
.
indexOf
(
row
)
>
-
1
;
return
acc
.
concat
(
this
.
wrappedRowRender
({
row
,
$index
:
acc
.
length
,
isSelected
,
isExpanded
}));
},
[])
},
[])
}
}
<
el
-
tooltip
effect
=
{
this
.
table
.
tooltipEffect
}
placement
=
"
top
"
ref
=
"
tooltip
"
content
=
{
this
.
tooltipContent
}
><
/el-tooltip
>
<
el
-
tooltip
effect
=
{
this
.
table
.
tooltipEffect
}
placement
=
"
top
"
ref
=
"
tooltip
"
content
=
{
this
.
tooltipContent
}
><
/el-tooltip
>
...
@@ -329,18 +320,8 @@ export default {
...
@@ -329,18 +320,8 @@ export default {
table
.
$emit
(
`row-
${
name
}
`
,
row
,
column
,
event
);
table
.
$emit
(
`row-
${
name
}
`
,
row
,
column
,
event
);
},
},
getRowHeight
(
rowKey
)
{
rowRender
(
row
,
$index
,
treeRowData
)
{
const
{
fixed
}
=
this
;
if
(
!
fixed
)
{
return
null
;
}
const
height
=
(
this
.
tableLayout
.
fixedColumnsBodyRowsHeight
||
{})[
rowKey
];
return
typeof
height
===
'
number
'
?
`
${
height
}
px`
:
height
;
},
rowRender
({
row
,
$index
,
treeRowData
,
isSelected
,
isExpanded
})
{
const
{
treeIndent
,
columns
,
firstDefaultColumnIndex
}
=
this
;
const
{
treeIndent
,
columns
,
firstDefaultColumnIndex
}
=
this
;
const
rowClasses
=
this
.
getRowClass
(
row
,
$index
);
const
rowClasses
=
this
.
getRowClass
(
row
,
$index
);
let
display
=
true
;
let
display
=
true
;
if
(
treeRowData
)
{
if
(
treeRowData
)
{
...
@@ -352,14 +333,9 @@ export default {
...
@@ -352,14 +333,9 @@ export default {
let
displayStyle
=
display
?
null
:
{
let
displayStyle
=
display
?
null
:
{
display
:
'
none
'
display
:
'
none
'
};
};
const
height
=
this
.
getRowHeight
(
$index
);
const
heightStyle
=
height
?
{
height
}
:
null
;
return
(
return
(
<
TableRow
<
TableRow
style
=
{[
displayStyle
,
this
.
getRowStyle
(
row
,
$index
)
,
heightStyle
]}
style
=
{[
displayStyle
,
this
.
getRowStyle
(
row
,
$index
)]}
class
=
{
rowClasses
}
class
=
{
rowClasses
}
key
=
{
this
.
getKeyOfRow
(
row
,
$index
)}
key
=
{
this
.
getKeyOfRow
(
row
,
$index
)}
nativeOn
-
dblclick
=
{(
$event
)
=>
this
.
handleDoubleClick
(
$event
,
row
)}
nativeOn
-
dblclick
=
{(
$event
)
=>
this
.
handleDoubleClick
(
$event
,
row
)}
...
@@ -382,21 +358,21 @@ export default {
...
@@ -382,21 +358,21 @@ export default {
getCellClass
=
{
this
.
getCellClass
}
getCellClass
=
{
this
.
getCellClass
}
handleCellMouseEnter
=
{
this
.
handleCellMouseEnter
}
handleCellMouseEnter
=
{
this
.
handleCellMouseEnter
}
handleCellMouseLeave
=
{
this
.
handleCellMouseLeave
}
handleCellMouseLeave
=
{
this
.
handleCellMouseLeave
}
isSelected
=
{
isSelected
}
isSelected
=
{
this
.
store
.
isSelected
(
row
)
}
isExpanded
=
{
isExpanded
}
isExpanded
=
{
this
.
store
.
states
.
expandRows
.
indexOf
(
row
)
>
-
1
}
fixed
=
{
this
.
fixed
}
fixed
=
{
this
.
fixed
}
>
>
<
/TableRow
>
<
/TableRow
>
);
);
},
},
wrappedRowRender
(
{
row
,
$index
,
isSelected
,
isExpanded
}
)
{
wrappedRowRender
(
row
,
$index
)
{
const
store
=
this
.
store
;
const
store
=
this
.
store
;
const
{
isRowExpanded
,
assertRowKey
}
=
store
;
const
{
isRowExpanded
,
assertRowKey
}
=
store
;
const
{
treeData
,
lazyTreeNodeMap
,
childrenColumnName
,
rowKey
}
=
store
.
states
;
const
{
treeData
,
lazyTreeNodeMap
,
childrenColumnName
,
rowKey
}
=
store
.
states
;
if
(
this
.
hasExpandColumn
&&
isRowExpanded
(
row
))
{
if
(
this
.
hasExpandColumn
&&
isRowExpanded
(
row
))
{
const
renderExpanded
=
this
.
table
.
renderExpanded
;
const
renderExpanded
=
this
.
table
.
renderExpanded
;
const
tr
=
this
.
rowRender
(
{
row
,
$index
,
isSelected
,
isExpanded
}
);
const
tr
=
this
.
rowRender
(
row
,
$index
);
if
(
!
renderExpanded
)
{
if
(
!
renderExpanded
)
{
console
.
error
(
'
[Element Error]renderExpanded is required.
'
);
console
.
error
(
'
[Element Error]renderExpanded is required.
'
);
return
tr
;
return
tr
;
...
@@ -429,7 +405,7 @@ export default {
...
@@ -429,7 +405,7 @@ export default {
treeRowData
.
loading
=
cur
.
loading
;
treeRowData
.
loading
=
cur
.
loading
;
}
}
}
}
const
tmp
=
[
this
.
rowRender
(
{
row
,
$index
,
treeRowData
,
isSelected
,
isExpanded
}
)];
const
tmp
=
[
this
.
rowRender
(
row
,
$index
,
treeRowData
)];
// 渲染嵌套数据
// 渲染嵌套数据
if
(
cur
)
{
if
(
cur
)
{
// currentRow 记录的是 index,所以还需主动增加 TreeTable 的 index
// currentRow 记录的是 index,所以还需主动增加 TreeTable 的 index
...
@@ -463,7 +439,7 @@ export default {
...
@@ -463,7 +439,7 @@ export default {
}
}
}
}
i
++
;
i
++
;
tmp
.
push
(
this
.
rowRender
(
{
row
:
node
,
$index
:
$index
+
i
,
treeRowData
:
innerTreeRowData
,
isSelected
,
isExpanded
}
));
tmp
.
push
(
this
.
rowRender
(
node
,
$index
+
i
,
innerTreeRowData
));
if
(
cur
)
{
if
(
cur
)
{
const
nodes
=
lazyTreeNodeMap
[
childKey
]
||
node
[
childrenColumnName
];
const
nodes
=
lazyTreeNodeMap
[
childKey
]
||
node
[
childrenColumnName
];
traverse
(
nodes
,
cur
);
traverse
(
nodes
,
cur
);
...
@@ -477,7 +453,7 @@ export default {
...
@@ -477,7 +453,7 @@ export default {
}
}
return
tmp
;
return
tmp
;
}
else
{
}
else
{
return
this
.
rowRender
(
{
row
,
$index
,
isSelected
,
isExpanded
}
);
return
this
.
rowRender
(
row
,
$index
);
}
}
}
}
}
}
...
...
packages/table/src/table-layout.js
View file @
3499c9e6
...
@@ -25,7 +25,6 @@ class TableLayout {
...
@@ -25,7 +25,6 @@ class TableLayout {
this
.
bodyHeight
=
null
;
// Table Height - Table Header Height
this
.
bodyHeight
=
null
;
// Table Height - Table Header Height
this
.
fixedBodyHeight
=
null
;
// Table Height - Table Header Height - Scroll Bar Height
this
.
fixedBodyHeight
=
null
;
// Table Height - Table Header Height - Scroll Bar Height
this
.
gutterWidth
=
scrollbarWidth
();
this
.
gutterWidth
=
scrollbarWidth
();
this
.
fixedColumnsBodyRowsHeight
=
{};
for
(
let
name
in
options
)
{
for
(
let
name
in
options
)
{
if
(
options
.
hasOwnProperty
(
name
))
{
if
(
options
.
hasOwnProperty
(
name
))
{
...
@@ -62,14 +61,13 @@ class TableLayout {
...
@@ -62,14 +61,13 @@ class TableLayout {
this
.
height
=
value
;
this
.
height
=
value
;
if
(
!
el
&&
(
value
||
value
===
0
))
return
Vue
.
nextTick
(()
=>
this
.
setHeight
(
value
,
prop
));
if
(
!
el
&&
(
value
||
value
===
0
))
return
Vue
.
nextTick
(()
=>
this
.
setHeight
(
value
,
prop
));
if
(
el
&&
el
.
style
)
{
if
(
typeof
value
===
'
number
'
)
{
if
(
typeof
value
===
'
number
'
)
{
el
.
style
[
prop
]
=
value
+
'
px
'
;
el
.
style
[
prop
]
=
value
+
'
px
'
;
this
.
updateElsHeight
();
this
.
updateElsHeight
();
}
else
if
(
typeof
value
===
'
string
'
)
{
}
else
if
(
typeof
value
===
'
string
'
)
{
el
.
style
[
prop
]
=
value
;
el
.
style
[
prop
]
=
value
;
this
.
updateElsHeight
();
this
.
updateElsHeight
();
}
}
}
}
}
...
@@ -115,40 +113,10 @@ class TableLayout {
...
@@ -115,40 +113,10 @@ class TableLayout {
const
noData
=
!
(
this
.
store
.
states
.
data
&&
this
.
store
.
states
.
data
.
length
);
const
noData
=
!
(
this
.
store
.
states
.
data
&&
this
.
store
.
states
.
data
.
length
);
this
.
viewportHeight
=
this
.
scrollX
?
tableHeight
-
(
noData
?
0
:
this
.
gutterWidth
)
:
tableHeight
;
this
.
viewportHeight
=
this
.
scrollX
?
tableHeight
-
(
noData
?
0
:
this
.
gutterWidth
)
:
tableHeight
;
setTimeout
(()
=>
{
this
.
syncFixedTableRowHeight
();
});
this
.
updateScrollY
();
this
.
updateScrollY
();
this
.
notifyObservers
(
'
scrollable
'
);
this
.
notifyObservers
(
'
scrollable
'
);
}
}
syncFixedTableRowHeight
()
{
const
fixedColumns
=
this
.
store
.
states
.
fixedColumns
;
const
rightFixedColumns
=
this
.
store
.
states
.
rightFixedColumns
;
if
(
fixedColumns
.
length
+
rightFixedColumns
.
length
===
0
)
{
return
;
}
const
{
bodyWrapper
}
=
this
.
table
.
$refs
;
const
tableRect
=
bodyWrapper
.
getBoundingClientRect
();
if
(
tableRect
.
height
!==
undefined
&&
tableRect
.
height
<=
0
)
{
return
;
}
const
bodyRows
=
bodyWrapper
.
querySelectorAll
(
'
.el-table__row
'
)
||
[];
const
fixedColumnsBodyRowsHeight
=
[].
reduce
.
call
(
bodyRows
,
(
acc
,
row
,
index
)
=>
{
const
height
=
row
.
getBoundingClientRect
().
height
||
'
auto
'
;
acc
[
index
]
=
height
;
return
acc
;
},
{}
);
this
.
fixedColumnsBodyRowsHeight
=
fixedColumnsBodyRowsHeight
;
};
headerDisplayNone
(
elm
)
{
headerDisplayNone
(
elm
)
{
if
(
!
elm
)
return
true
;
if
(
!
elm
)
return
true
;
let
headerChild
=
elm
;
let
headerChild
=
elm
;
...
...
packages/table/src/table.vue
View file @
3499c9e6
...
@@ -115,7 +115,7 @@
...
@@ -115,7 +115,7 @@
:row-class-name=
"rowClassName"
:row-class-name=
"rowClassName"
:row-style=
"rowStyle"
:row-style=
"rowStyle"
:style=
"
{
:style=
"
{
width:
layout.fixedWidth ? layout.fixedWidth + 'px' : ''
width:
bodyWidth
}">
}">
</table-body>
</table-body>
<div
<div
...
@@ -176,7 +176,7 @@
...
@@ -176,7 +176,7 @@
:row-style=
"rowStyle"
:row-style=
"rowStyle"
:highlight=
"highlightCurrentRow"
:highlight=
"highlightCurrentRow"
:style=
"
{
:style=
"
{
width:
layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
width:
bodyWidth
}">
}">
</table-body>
</table-body>
<div
<div
...
@@ -412,7 +412,7 @@
...
@@ -412,7 +412,7 @@
},
},
// TODO 使用 CSS transform
// TODO 使用 CSS transform
syncPostion
:
throttle
(
20
,
function
()
{
syncPostion
()
{
const
{
scrollLeft
,
scrollTop
,
offsetWidth
,
scrollWidth
}
=
this
.
bodyWrapper
;
const
{
scrollLeft
,
scrollTop
,
offsetWidth
,
scrollWidth
}
=
this
.
bodyWrapper
;
const
{
headerWrapper
,
footerWrapper
,
fixedBodyWrapper
,
rightFixedBodyWrapper
}
=
this
.
$refs
;
const
{
headerWrapper
,
footerWrapper
,
fixedBodyWrapper
,
rightFixedBodyWrapper
}
=
this
.
$refs
;
if
(
headerWrapper
)
headerWrapper
.
scrollLeft
=
scrollLeft
;
if
(
headerWrapper
)
headerWrapper
.
scrollLeft
=
scrollLeft
;
...
@@ -427,17 +427,30 @@
...
@@ -427,17 +427,30 @@
}
else
{
}
else
{
this
.
scrollPosition
=
'
middle
'
;
this
.
scrollPosition
=
'
middle
'
;
}
}
},
throttleSyncPostion
:
throttle
(
16
,
function
()
{
this
.
syncPostion
();
}),
}),
onScroll
(
evt
)
{
let
raf
=
window
.
requestAnimationFrame
;
if
(
!
raf
)
{
this
.
throttleSyncPostion
();
}
else
{
raf
(
this
.
syncPostion
);
}
},
bindEvents
()
{
bindEvents
()
{
this
.
bodyWrapper
.
addEventListener
(
'
scroll
'
,
this
.
syncPostion
,
{
passive
:
true
});
this
.
bodyWrapper
.
addEventListener
(
'
scroll
'
,
this
.
onScroll
,
{
passive
:
true
});
if
(
this
.
fit
)
{
if
(
this
.
fit
)
{
addResizeListener
(
this
.
$el
,
this
.
resizeListener
);
addResizeListener
(
this
.
$el
,
this
.
resizeListener
);
}
}
},
},
unbindEvents
()
{
unbindEvents
()
{
this
.
bodyWrapper
.
removeEventListener
(
'
scroll
'
,
this
.
syncPostion
,
{
passive
:
true
});
this
.
bodyWrapper
.
removeEventListener
(
'
scroll
'
,
this
.
onScroll
,
{
passive
:
true
});
if
(
this
.
fit
)
{
if
(
this
.
fit
)
{
removeResizeListener
(
this
.
$el
,
this
.
resizeListener
);
removeResizeListener
(
this
.
$el
,
this
.
resizeListener
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment