Skip to content

Commit 44a8381

Browse files
committed
v2.9.0
添加实例方法: 1、行高亮选中
1 parent a4ba3dd commit 44a8381

File tree

10 files changed

+76
-7
lines changed

10 files changed

+76
-7
lines changed

examples/src/docs/en/ve-table/api/db.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ export const db = {
471471
desc: `Scroll the table to the location of the row key`,
472472
param: "{rowKey}",
473473
},
474+
{
475+
name: "setHighlightRow",
476+
desc: `Set highlight row <a href='#/en/doc/table/row-style?anchor=row-click-highlight'>Refer To Demo</a>`,
477+
param: "{rowKey}",
478+
},
474479
],
475480
columns: columnsType2,
476481
},

examples/src/docs/en/ve-table/row-style/click-highlight.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
:::anchor Row Click highlight
22

3-
:::demo By default, line click highlight is on, Must set `row-key-field-name`
3+
:::demo 1、By default, line click highlight is on, Must set `row-key-field-name`<br>2、You can set the highlighted row through the `setHighlightRow` instance method
44

55
```html
66
<template>
77
<div>
8+
<button class="button-demo" @click="setHighlightRow(1002)">Highlight Row 2</button>
9+
<br />
10+
<br />
811
<ve-table
12+
ref="tableRef"
913
:row-style-option="rowStyleOption"
1014
:columns="columns"
1115
:table-data="tableData"
@@ -93,6 +97,12 @@
9397
],
9498
};
9599
},
100+
methods: {
101+
// set highlight row
102+
setHighlightRow(rowKey) {
103+
this.$refs["tableRef"].setHighlightRow({ rowKey: rowKey });
104+
},
105+
},
96106
};
97107
</script>
98108
```

examples/src/docs/zh/ve-table/api/db.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ export const db = {
471471
desc: `将表格滚动到行为rowKey的位置`,
472472
param: "{rowKey}",
473473
},
474+
{
475+
name: "setHighlightRow",
476+
desc: `设置高亮的行 <a href='#/zh/doc/table/row-style?anchor=row-click-highlight'>参考示例</a>`,
477+
param: "{rowKey}",
478+
},
474479
],
475480
columns: columnsType2,
476481
},

examples/src/docs/zh/ve-table/row-style/click-highlight.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
:::anchor 行 click 高亮
22

3-
:::demo 默认行 click 高亮效果开启。要设置`row-key-field-name`
3+
:::demo 1、默认行 click 高亮效果开启。要设置`row-key-field-name`<br>2、可以通过 `setHighlightRow`实例方法设置高亮行
44

55
```html
66
<template>
77
<div>
8+
<button class="button-demo" @click="setHighlightRow(1002)">选中第2行</button>
9+
<br />
10+
<br />
811
<ve-table
12+
ref="tableRef"
913
:row-style-option="rowStyleOption"
1014
:columns="columns"
1115
:table-data="tableData"
@@ -93,6 +97,12 @@
9397
],
9498
};
9599
},
100+
methods: {
101+
// set highlight row
102+
setHighlightRow(rowKey) {
103+
this.$refs["tableRef"].setHighlightRow({ rowKey: rowKey });
104+
},
105+
},
96106
};
97107
</script>
98108
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-easytable",
3-
"version": "2.8.3",
3+
"version": "2.9.0",
44
"main": "libs/main.js",
55
"description": "Vue table component",
66
"keywords": [

packages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import VeSelect from './ve-select';
1212
import VeTable from './ve-table';
1313

1414

15-
const version = '2.8.3';
15+
const version = '2.9.0';
1616
const components = [
1717
VeCheckbox,
1818
VeCheckboxGroup,

packages/ve-table/src/body/index.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export default {
8888
return null;
8989
},
9090
},
91+
// highlight row key
92+
highlightRowKey: {
93+
type: [String, Number],
94+
default: null,
95+
},
9196
// event custom option
9297
eventCustomOption: {
9398
type: Object,
@@ -134,8 +139,6 @@ export default {
134139
1、存储当前单选功能的rowkey 信息
135140
*/
136141
internalRadioSelectedRowKey: null,
137-
// highlight row key
138-
highlightRowKey: "",
139142
};
140143
},
141144
// 存储非响应式数据
@@ -383,7 +386,7 @@ export default {
383386
// 行高亮功能
384387
if (rowKeyFieldName) {
385388
const rowKey = rowData[rowKeyFieldName];
386-
this.highlightRowKey = rowKey;
389+
this.$emit(EMIT_EVENTS.HIGHLIGHT_ROW_CHANGE, { rowKey });
387390
}
388391

389392
// 行展开功能

packages/ve-table/src/index.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ export default {
239239
2、当 max-height="calc(100vh - 210px)" 或者 max-height="80%" 时使用 tableOffestHeight
240240
*/
241241
tableOffestHeight: 0,
242+
// highlight row key
243+
highlightRowKey: "",
242244
};
243245
},
244246
// 存储非响应式数据
@@ -1097,6 +1099,10 @@ export default {
10971099
behavior: "smooth",
10981100
});
10991101
},
1102+
// set highlight row
1103+
[INSTANCE_METHODS.SET_HIGHLIGHT_ROW]({ rowKey }) {
1104+
this.highlightRowKey = rowKey;
1105+
},
11001106
},
11011107
mounted() {
11021108
// receive row selected change
@@ -1200,11 +1206,14 @@ export default {
12001206
cellSelectionKeyData: this.cellSelectionKeyData,
12011207
allRowKeys: this.allRowKeys,
12021208
editOption: this.editOption,
1209+
highlightRowKey: this.highlightRowKey,
12031210
},
12041211
on: {
12051212
[EMIT_EVENTS.BODY_TD_WIDTH_CHANGE]: tdWidthChange,
12061213
[EMIT_EVENTS.CELL_SELECTION_KEY_CHANGE]:
12071214
this.cellSelectionKeyChange,
1215+
[EMIT_EVENTS.HIGHLIGHT_ROW_CHANGE]:
1216+
this[INSTANCE_METHODS.SET_HIGHLIGHT_ROW],
12081217
},
12091218
};
12101219

packages/ve-table/src/util/constant.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export const EMIT_EVENTS = {
5656
HEADER_FILTER_CONFIRM: "on-filter-confirm",
5757
// header filter reset
5858
HEADER_FILTER_RESET: "on-filter-reset",
59+
// highlight row change
60+
HIGHLIGHT_ROW_CHANGE: "on-highlight-row-change",
5961
};
6062

6163
// comps name
@@ -90,4 +92,6 @@ export const INSTANCE_METHODS = {
9092
SCROLL_TO: "scrollTo",
9193
// scroll to rowKey
9294
SCROLL_TO_ROW_KEY: "scrollToRowKey",
95+
// set highlight row
96+
SET_HIGHLIGHT_ROW: "setHighlightRow",
9397
};

tests/unit/specs/ve-table-row-style.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,27 @@ describe("veTable row style", () => {
123123

124124
expect(firstTr.classes()).toContain("ve-table-tr-highlight");
125125
});
126+
127+
it("row highlight by setHighlightRow method", async () => {
128+
const wrapper = mount(veTable, {
129+
propsData: {
130+
columns: COLUMNS,
131+
tableData: TABLE_DATA,
132+
rowStyleOption: {
133+
stripe: true,
134+
hoverHighlight: true,
135+
clickHighlight: true,
136+
},
137+
rowKeyFieldName: "rowKey",
138+
},
139+
});
140+
141+
wrapper.vm.setHighlightRow({ rowKey: 2 });
142+
143+
await later();
144+
145+
const highlightRow = wrapper.findAll(".ve-table-body-tr").at(2);
146+
147+
expect(highlightRow.classes()).toContain("ve-table-tr-highlight");
148+
});
126149
});

0 commit comments

Comments
 (0)