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
0a31868b
Commit
0a31868b
authored
Nov 18, 2016
by
furybean
Committed by
Leopoldthecoder
Nov 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table: add show-header prop & add header-click event & make height more reasonable.
parent
4e423144
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
16 deletions
+71
-16
examples/docs/en-US/table.md
examples/docs/en-US/table.md
+2
-0
examples/docs/zh-CN/table.md
examples/docs/zh-CN/table.md
+3
-1
packages/table/src/table-header.js
packages/table/src/table-header.js
+6
-1
packages/table/src/table-layout.js
packages/table/src/table-layout.js
+27
-10
packages/table/src/table.vue
packages/table/src/table.vue
+10
-4
test/unit/specs/table.spec.js
test/unit/specs/table.spec.js
+23
-0
No files found.
examples/docs/en-US/table.md
View file @
0a31868b
...
@@ -1072,6 +1072,7 @@ Customize table column so it can be integrated with other components.
...
@@ -1072,6 +1072,7 @@ Customize table column so it can be integrated with other components.
| stripe | whether table is striped | boolean | — | false |
| stripe | whether table is striped | boolean | — | false |
| border | whether table has vertical border | boolean | — | false |
| border | whether table has vertical border | boolean | — | false |
| fit | whether width of column automatically fits its container | boolean | — | true |
| fit | whether width of column automatically fits its container | boolean | — | true |
| show-header | whether table header is visible | boolean | - | true |
| highlight-current-row | whether current row is highlighted | boolean | — | false |
| highlight-current-row | whether current row is highlighted | boolean | — | false |
| row-class-name | function that returns custom class names for a row | Function(row, index) | — | — |
| row-class-name | function that returns custom class names for a row | Function(row, index) | — | — |
| row-key | key of row data, used for optimizing rendering. Required if
`reserve-selection`
is on | Function(row)/String | — | — |
| row-key | key of row data, used for optimizing rendering. Required if
`reserve-selection`
is on | Function(row)/String | — | — |
...
@@ -1087,6 +1088,7 @@ Customize table column so it can be integrated with other components.
...
@@ -1087,6 +1088,7 @@ Customize table column so it can be integrated with other components.
| cell-mouse-leave | triggers when hovering out of a cell | row, column, cell, event |
| cell-mouse-leave | triggers when hovering out of a cell | row, column, cell, event |
| cell-click | triggers when clicking a cell | row, column, cell, event |
| cell-click | triggers when clicking a cell | row, column, cell, event |
| row-click | triggers when clicking a row | row, event |
| row-click | triggers when clicking a row | row, event |
| header-click | triggers when clicking a column header | column, event |
| sort-change | triggers when Table's sorting changes | { column, prop, order } |
| sort-change | triggers when Table's sorting changes | { column, prop, order } |
| current-change | triggers when current row changes | currentRow, oldCurrentRow |
| current-change | triggers when current row changes | currentRow, oldCurrentRow |
...
...
examples/docs/zh-CN/table.md
View file @
0a31868b
...
@@ -1073,10 +1073,11 @@
...
@@ -1073,10 +1073,11 @@
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------------- |---------- |-------------------------------- |-------- |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| data | 显示的数据 | array | — | — |
| data | 显示的数据 | array | — | — |
| height |
table 的高度,默认高度为空,即自动高度,单位 px
| string/number | — | — |
| height |
Table 的高度,默认为自动高度。如果 height 为 number 类型,单位 px;如果 height 为 string 类型,则 Table 的高度受控于外部样式。
| string/number | — | — |
| stripe | 是否为斑马纹 table | boolean | — | false |
| stripe | 是否为斑马纹 table | boolean | — | false |
| border | 是否带有纵向边框 | boolean | — | false |
| border | 是否带有纵向边框 | boolean | — | false |
| fit | 列的宽度是否自撑开 | boolean | — | true |
| fit | 列的宽度是否自撑开 | boolean | — | true |
| show-header | 是否显示表头 | boolean | - | true |
| highlight-current-row | 是否要高亮当前行 | boolean | — | false |
| highlight-current-row | 是否要高亮当前行 | boolean | — | false |
| row-class-name | 行的 className 的回调。 | Function(row, index) | — | — |
| row-class-name | 行的 className 的回调。 | Function(row, index) | — | — |
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的 | Function(row)/String | — | — |
| row-key | 行数据的 Key,用来优化 Table 的渲染;在使用 reserve-selection 功能的情况下,该属性是必填的 | Function(row)/String | — | — |
...
@@ -1092,6 +1093,7 @@
...
@@ -1092,6 +1093,7 @@
| cell-mouse-leave | 当单元格 hover 退出时会触发该事件 | row, column, cell, event |
| cell-mouse-leave | 当单元格 hover 退出时会触发该事件 | row, column, cell, event |
| cell-click | 当某个单元格被点击时会触发该事件 | row, column, cell, event |
| cell-click | 当某个单元格被点击时会触发该事件 | row, column, cell, event |
| row-click | 当某一行被点击时会触发该事件 | row, event |
| row-click | 当某一行被点击时会触发该事件 | row, event |
| header-click | 当某一列的表头被点击时会触发该事件 | column, event |
| sort-change | 当表格的排序条件发生变化的时候会触发该事件 | { column, prop, order } |
| sort-change | 当表格的排序条件发生变化的时候会触发该事件 | { column, prop, order } |
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | currentRow, oldCurrentRow |
| current-change | 当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性 | currentRow, oldCurrentRow |
...
...
packages/table/src/table-header.js
View file @
0a31868b
...
@@ -33,6 +33,7 @@ export default {
...
@@ -33,6 +33,7 @@ export default {
on
-
mousemove
=
{
(
$event
)
=>
this
.
handleMouseMove
(
$event
,
column
)
}
on
-
mousemove
=
{
(
$event
)
=>
this
.
handleMouseMove
(
$event
,
column
)
}
on
-
mouseout
=
{
this
.
handleMouseOut
}
on
-
mouseout
=
{
this
.
handleMouseOut
}
on
-
mousedown
=
{
(
$event
)
=>
this
.
handleMouseDown
(
$event
,
column
)
}
on
-
mousedown
=
{
(
$event
)
=>
this
.
handleMouseDown
(
$event
,
column
)
}
on
-
click
=
{
(
$event
)
=>
this
.
handleClick
(
$event
,
column
)
}
class
=
{
[
column
.
id
,
column
.
order
,
column
.
align
,
column
.
className
||
''
,
this
.
isCellHidden
(
cellIndex
)
?
'
is-hidden
'
:
''
]
}
>
class
=
{
[
column
.
id
,
column
.
order
,
column
.
align
,
column
.
className
||
''
,
this
.
isCellHidden
(
cellIndex
)
?
'
is-hidden
'
:
''
]
}
>
<
div
class
=
{
[
'
cell
'
,
column
.
filteredValue
&&
column
.
filteredValue
.
length
>
0
?
'
highlight
'
:
''
]
}
>
<
div
class
=
{
[
'
cell
'
,
column
.
filteredValue
&&
column
.
filteredValue
.
length
>
0
?
'
highlight
'
:
''
]
}
>
{
{
...
@@ -162,6 +163,10 @@ export default {
...
@@ -162,6 +163,10 @@ export default {
},
16
);
},
16
);
},
},
handleClick
(
event
,
column
)
{
this
.
$parent
.
$emit
(
'
header-click
'
,
column
,
event
);
},
handleMouseDown
(
event
,
column
)
{
handleMouseDown
(
event
,
column
)
{
/* istanbul ignore if */
/* istanbul ignore if */
if
(
this
.
draggingColumn
&&
this
.
border
)
{
if
(
this
.
draggingColumn
&&
this
.
border
)
{
...
@@ -239,7 +244,7 @@ export default {
...
@@ -239,7 +244,7 @@ export default {
if
(
!
this
.
dragging
&&
this
.
border
)
{
if
(
!
this
.
dragging
&&
this
.
border
)
{
let
rect
=
target
.
getBoundingClientRect
();
let
rect
=
target
.
getBoundingClientRect
();
var
bodyStyle
=
document
.
body
.
style
;
const
bodyStyle
=
document
.
body
.
style
;
if
(
rect
.
width
>
12
&&
rect
.
right
-
event
.
pageX
<
8
)
{
if
(
rect
.
width
>
12
&&
rect
.
right
-
event
.
pageX
<
8
)
{
bodyStyle
.
cursor
=
'
col-resize
'
;
bodyStyle
.
cursor
=
'
col-resize
'
;
this
.
draggingColumn
=
column
;
this
.
draggingColumn
=
column
;
...
...
packages/table/src/table-layout.js
View file @
0a31868b
...
@@ -8,6 +8,7 @@ class TableLayout {
...
@@ -8,6 +8,7 @@ class TableLayout {
this
.
store
=
null
;
this
.
store
=
null
;
this
.
columns
=
null
;
this
.
columns
=
null
;
this
.
fit
=
true
;
this
.
fit
=
true
;
this
.
showHeader
=
true
;
this
.
height
=
null
;
this
.
height
=
null
;
this
.
scrollX
=
false
;
this
.
scrollX
=
false
;
...
@@ -50,16 +51,21 @@ class TableLayout {
...
@@ -50,16 +51,21 @@ class TableLayout {
}
}
setHeight
(
height
)
{
setHeight
(
height
)
{
if
(
typeof
height
===
'
string
'
&&
/^
\d
+$/
.
test
(
height
))
{
const
el
=
this
.
table
.
$el
;
height
=
Number
(
height
);
if
(
typeof
height
===
'
string
'
)
{
if
(
/^
\d
+$/
.
test
(
height
))
{
height
=
Number
(
height
);
}
}
}
this
.
height
=
height
;
this
.
height
=
height
;
const
el
=
this
.
table
.
$el
;
if
(
!
el
)
return
;
if
(
!
isNaN
(
height
)
&&
el
)
{
if
(
!
isNaN
(
height
))
{
el
.
style
.
height
=
height
+
'
px
'
;
el
.
style
.
height
=
height
+
'
px
'
;
this
.
updateHeight
();
}
else
if
(
typeof
height
===
'
string
'
)
{
this
.
updateHeight
();
this
.
updateHeight
();
}
}
}
}
...
@@ -67,12 +73,23 @@ class TableLayout {
...
@@ -67,12 +73,23 @@ class TableLayout {
updateHeight
()
{
updateHeight
()
{
const
height
=
this
.
tableHeight
=
this
.
table
.
$el
.
clientHeight
;
const
height
=
this
.
tableHeight
=
this
.
table
.
$el
.
clientHeight
;
const
{
headerWrapper
}
=
this
.
table
.
$refs
;
const
{
headerWrapper
}
=
this
.
table
.
$refs
;
if
(
!
headerWrapper
)
return
;
if
(
this
.
showHeader
&&
!
headerWrapper
)
return
;
const
headerHeight
=
this
.
headerHeight
=
headerWrapper
.
offsetHeight
;
if
(
!
this
.
showHeader
)
{
const
bodyHeight
=
height
-
headerHeight
;
this
.
headerHeight
=
0
;
if
(
this
.
height
!==
null
&&
!
isNaN
(
this
.
height
))
this
.
bodyHeight
=
bodyHeight
;
if
(
this
.
height
!==
null
&&
(
!
isNaN
(
this
.
height
)
||
typeof
this
.
height
===
'
string
'
))
{
this
.
fixedBodyHeight
=
this
.
scrollX
?
bodyHeight
-
this
.
gutterWidth
:
bodyHeight
;
this
.
bodyHeight
=
height
;
this
.
viewportHeight
=
this
.
scrollX
?
height
-
this
.
gutterWidth
:
height
;
}
this
.
fixedBodyHeight
=
this
.
scrollX
?
height
-
this
.
gutterWidth
:
height
;
this
.
viewportHeight
=
this
.
scrollX
?
height
-
this
.
gutterWidth
:
height
;
}
else
{
const
headerHeight
=
this
.
headerHeight
=
headerWrapper
.
offsetHeight
;
const
bodyHeight
=
height
-
headerHeight
;
if
(
this
.
height
!==
null
&&
(
!
isNaN
(
this
.
height
)
||
typeof
this
.
height
===
'
string
'
))
{
this
.
bodyHeight
=
bodyHeight
;
}
this
.
fixedBodyHeight
=
this
.
scrollX
?
bodyHeight
-
this
.
gutterWidth
:
bodyHeight
;
this
.
viewportHeight
=
this
.
scrollX
?
height
-
this
.
gutterWidth
:
height
;
}
}
}
update
()
{
update
()
{
...
...
packages/table/src/table.vue
View file @
0a31868b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
:class=
"
{ 'el-table--fit': fit, 'el-table--striped': stripe, 'el-table--border': border }"
:class=
"
{ 'el-table--fit': fit, 'el-table--striped': stripe, 'el-table--border': border }"
@mouseleave="handleMouseLeave($event)">
@mouseleave="handleMouseLeave($event)">
<div
class=
"hidden-columns"
ref=
"hiddenColumns"
><slot></slot></div>
<div
class=
"hidden-columns"
ref=
"hiddenColumns"
><slot></slot></div>
<div
class=
"el-table__header-wrapper"
ref=
"headerWrapper"
>
<div
class=
"el-table__header-wrapper"
ref=
"headerWrapper"
v-if=
"showHeader"
>
<table-header
<table-header
:store=
"store"
:store=
"store"
:layout=
"layout"
:layout=
"layout"
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
width: layout.fixedWidth ? layout.fixedWidth + 'px' : '',
width: layout.fixedWidth ? layout.fixedWidth + 'px' : '',
height: layout.viewportHeight ? layout.viewportHeight + 'px' : ''
height: layout.viewportHeight ? layout.viewportHeight + 'px' : ''
}">
}">
<div
class=
"el-table__fixed-header-wrapper"
ref=
"fixedHeaderWrapper"
>
<div
class=
"el-table__fixed-header-wrapper"
ref=
"fixedHeaderWrapper"
v-if=
"showHeader"
>
<table-header
<table-header
fixed=
"left"
fixed=
"left"
:border=
"border"
:border=
"border"
...
@@ -61,7 +61,7 @@
...
@@ -61,7 +61,7 @@
height: layout.viewportHeight ? layout.viewportHeight + 'px' : '',
height: layout.viewportHeight ? layout.viewportHeight + 'px' : '',
right: layout.scrollY ? layout.gutterWidth + 'px' : ''
right: layout.scrollY ? layout.gutterWidth + 'px' : ''
}">
}">
<div
class=
"el-table__fixed-header-wrapper"
ref=
"rightFixedHeaderWrapper"
>
<div
class=
"el-table__fixed-header-wrapper"
ref=
"rightFixedHeaderWrapper"
v-if=
"showHeader"
>
<table-header
<table-header
fixed=
"right"
fixed=
"right"
:border=
"border"
:border=
"border"
...
@@ -132,6 +132,11 @@
...
@@ -132,6 +132,11 @@
context
:
{},
context
:
{},
showHeader
:
{
type
:
Boolean
,
default
:
true
},
rowClassName
:
[
String
,
Function
],
rowClassName
:
[
String
,
Function
],
highlightCurrentRow
:
Boolean
,
highlightCurrentRow
:
Boolean
,
...
@@ -290,7 +295,8 @@
...
@@ -290,7 +295,8 @@
const
layout
=
new
TableLayout
({
const
layout
=
new
TableLayout
({
store
,
store
,
table
:
this
,
table
:
this
,
fit
:
this
.
fit
fit
:
this
.
fit
,
showHeader
:
this
.
showHeader
});
});
return
{
return
{
store
,
store
,
...
...
test/unit/specs/table.spec.js
View file @
0a31868b
...
@@ -116,6 +116,15 @@ describe('Table', () => {
...
@@ -116,6 +116,15 @@ describe('Table', () => {
},
DELAY
);
},
DELAY
);
});
});
it
(
'
show-header
'
,
done
=>
{
const
vm
=
createTable
(
'
:show-header="false"
'
);
setTimeout
(
_
=>
{
expect
(
vm
.
$el
.
querySelectorAll
(
'
.el-table__header-wrapper
'
).
length
).
to
.
equal
(
0
);
destroyVM
(
vm
);
done
();
},
DELAY
);
});
it
(
'
tableRowClassName
'
,
done
=>
{
it
(
'
tableRowClassName
'
,
done
=>
{
const
vm
=
createTable
(
'
:row-class-name="tableRowClassName"
'
,
{
const
vm
=
createTable
(
'
:row-class-name="tableRowClassName"
'
,
{
methods
:
{
methods
:
{
...
@@ -384,6 +393,20 @@ describe('Table', () => {
...
@@ -384,6 +393,20 @@ describe('Table', () => {
},
DELAY
);
},
DELAY
);
},
DELAY
);
},
DELAY
);
});
});
it
(
'
header-click
'
,
done
=>
{
const
vm
=
createTable
(
'
header-click
'
);
setTimeout
(
_
=>
{
const
cell
=
vm
.
$el
.
querySelectorAll
(
'
.el-table__header th
'
)[
1
];
// header[prop='name']
triggerEvent
(
cell
,
'
click
'
);
expect
(
vm
.
result
).
to
.
length
(
2
);
// column, event
expect
(
vm
.
result
[
0
]).
to
.
have
.
property
(
'
property
'
).
to
.
equal
(
'
name
'
);
destroyVM
(
vm
);
done
();
},
DELAY
);
});
});
});
describe
(
'
column attributes
'
,
()
=>
{
describe
(
'
column attributes
'
,
()
=>
{
...
...
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