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
eddf8527
Commit
eddf8527
authored
Aug 29, 2019
by
hetech
Committed by
GitHub
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table: fix setCurrentRow unable to clear highlight row (#16879)
parent
f7e31035
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
21 deletions
+63
-21
packages/table/src/store/current.js
packages/table/src/store/current.js
+27
-20
packages/table/src/store/index.js
packages/table/src/store/index.js
+1
-1
test/unit/specs/table.spec.js
test/unit/specs/table.spec.js
+35
-0
No files found.
packages/table/src/store/current.js
View file @
eddf8527
...
@@ -35,34 +35,41 @@ export default {
...
@@ -35,34 +35,41 @@ export default {
},
},
updateCurrentRow
(
currentRow
)
{
updateCurrentRow
(
currentRow
)
{
const
{
states
,
table
}
=
this
;
const
oldCurrentRow
=
states
.
currentRow
;
if
(
currentRow
&&
currentRow
!==
oldCurrentRow
)
{
states
.
currentRow
=
currentRow
;
table
.
$emit
(
'
current-change
'
,
currentRow
,
oldCurrentRow
);
return
;
}
if
(
!
currentRow
&&
oldCurrentRow
)
{
states
.
currentRow
=
null
;
table
.
$emit
(
'
current-change
'
,
null
,
oldCurrentRow
);
}
},
updateCurrentRowData
()
{
const
{
states
,
table
}
=
this
;
const
{
states
,
table
}
=
this
;
const
{
rowKey
,
_currentRowKey
}
=
states
;
const
{
rowKey
,
_currentRowKey
}
=
states
;
// data 为 null 时,结构时的默认值会被忽略
// data 为 null 时,结构时的默认值会被忽略
const
data
=
states
.
data
||
[];
const
data
=
states
.
data
||
[];
const
oldCurrentRow
=
states
.
currentRow
;
const
oldCurrentRow
=
states
.
currentRow
;
if
(
currentRow
)
{
// 当 currentRow 不在 data 中时尝试更新数据
this
.
restoreCurrentRowKey
();
if
(
data
.
indexOf
(
oldCurrentRow
)
===
-
1
&&
oldCurrentRow
)
{
states
.
currentRow
=
currentRow
;
if
(
rowKey
)
{
if
(
oldCurrentRow
!==
currentRow
)
{
const
currentRowKey
=
getRowIdentity
(
oldCurrentRow
,
rowKey
);
this
.
table
.
$emit
(
'
current-change
'
,
currentRow
,
oldCurrentRow
);
this
.
setCurrentRowByKey
(
currentRowKey
);
}
else
{
states
.
currentRow
=
null
;
}
}
}
else
{
if
(
states
.
currentRow
===
null
)
{
// 当 currentRow 不在 data 中时尝试更新数据
table
.
$emit
(
'
current-change
'
,
null
,
oldCurrentRow
);
if
(
data
.
indexOf
(
oldCurrentRow
)
===
-
1
&&
oldCurrentRow
)
{
this
.
restoreCurrentRowKey
();
if
(
rowKey
)
{
const
currentRowKey
=
getRowIdentity
(
oldCurrentRow
,
rowKey
);
this
.
setCurrentRowByKey
(
currentRowKey
);
}
else
{
states
.
currentRow
=
null
;
}
if
(
states
.
currentRow
!==
oldCurrentRow
)
{
table
.
$emit
(
'
current-change
'
,
null
,
oldCurrentRow
);
}
}
else
if
(
_currentRowKey
)
{
this
.
setCurrentRowByKey
(
_currentRowKey
);
}
}
}
else
if
(
_currentRowKey
)
{
// 把初始时下设置的 rowKey 转化成 rowData
this
.
setCurrentRowByKey
(
_currentRowKey
);
this
.
restoreCurrentRowKey
();
}
}
}
}
}
}
...
...
packages/table/src/store/index.js
View file @
eddf8527
...
@@ -10,7 +10,7 @@ Watcher.prototype.mutations = {
...
@@ -10,7 +10,7 @@ Watcher.prototype.mutations = {
this
.
execQuery
();
this
.
execQuery
();
// 数据变化,更新部分数据。
// 数据变化,更新部分数据。
// 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
// 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
this
.
updateCurrentRow
();
this
.
updateCurrentRow
Data
();
this
.
updateExpandRows
();
this
.
updateExpandRows
();
if
(
states
.
reserveSelection
)
{
if
(
states
.
reserveSelection
)
{
this
.
assertRowKey
();
this
.
assertRowKey
();
...
...
test/unit/specs/table.spec.js
View file @
eddf8527
...
@@ -1843,6 +1843,41 @@ describe('Table', () => {
...
@@ -1843,6 +1843,41 @@ describe('Table', () => {
assertSortIconCount
(
vm
.
$el
,
'
sorting icon is not one after sort same column
'
);
assertSortIconCount
(
vm
.
$el
,
'
sorting icon is not one after sort same column
'
);
destroyVM
(
vm
);
destroyVM
(
vm
);
});
});
it
(
'
setCurrentRow
'
,
async
()
=>
{
const
vm
=
createVue
({
template
:
`
<div>
<el-table ref="table" :data="testData" highlight-current-row>
<el-table-column prop="name" sortable />
<el-table-column prop="release" sortable />
<el-table-column prop="director" sortable />
<el-table-column prop="runtime" sortable />
</el-table>
<button class="clear" @click="clear">clear</button>
</div>
`
,
data
()
{
return
{
testData
:
getTestData
()
};
},
methods
:
{
clear
()
{
this
.
$refs
.
table
.
setCurrentRow
();
}
}
});
vm
.
$refs
.
table
.
setCurrentRow
(
vm
.
testData
[
1
]);
await
waitImmediate
();
const
secondRow
=
vm
.
$el
.
querySelectorAll
(
'
.el-table__row
'
)[
1
];
expect
(
secondRow
.
classList
.
contains
(
'
current-row
'
)).
to
.
true
;
vm
.
$el
.
querySelector
(
'
.clear
'
).
click
();
await
waitImmediate
();
expect
(
secondRow
.
classList
.
contains
(
'
current-row
'
)).
to
.
false
;
destroyVM
(
vm
);
});
});
});
it
(
'
hover
'
,
async
()
=>
{
it
(
'
hover
'
,
async
()
=>
{
...
...
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