Skip to content

Commit 97deae9

Browse files
committed
add scroll method
1 parent ab4575c commit 97deae9

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

Diff for: .prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/*
1+
tests/unit/coverage
22

33
.github/*
44

Diff for: examples/src/demo/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
fixed-header
7979
border-y
8080
max-height="calc(100vh - 210px)"
81-
scroll-width="calc(100vw + 300px)"
81+
scroll-width="calc(120vw)"
8282
:sort-option="sortOption"
8383
:virtual-scroll-option="virtualScrollOption"
8484
:columns="columns"

Diff for: packages/ve-table/src/index.jsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
} from "./util";
77
import { getValByUnit, isFunction, isNumber } from "../../src/utils/index.js";
88
import emitter from "../../src/mixins/emitter";
9-
import { COMPS_NAME, EMIT_EVENTS, COMPS_CUSTOM_ATTRS } from "./util/constant";
9+
import {
10+
COMPS_NAME,
11+
EMIT_EVENTS,
12+
COMPS_CUSTOM_ATTRS,
13+
TABLE_METHODS,
14+
} from "./util/constant";
1015
import Colgroup from "./colgroup";
1116
import Header from "./header";
1217
import Body from "./body";
@@ -1007,6 +1012,11 @@ export default {
10071012
};
10081013
}
10091014
},
1015+
1016+
// table scroll
1017+
[TABLE_METHODS.SCROLL](options) {
1018+
this.$refs[this.tableContainerRef].scroll(options);
1019+
},
10101020
},
10111021
mounted() {
10121022
// receive row selected change

Diff for: packages/ve-table/src/util/constant.js

+5
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ export const COMPS_CUSTOM_ATTRS = {
8383
// body row key
8484
BODY_ROW_KEY: "row-key",
8585
};
86+
87+
// table methods
88+
export const TABLE_METHODS = {
89+
SCROLL: "scroll",
90+
};

Diff for: tests/unit/specs/ve-table-methods.spec.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { mount } from "@vue/test-utils";
2+
import veTable from "@/ve-table";
3+
4+
describe("veTable methods", () => {
5+
const TABLE_DATA = [
6+
{
7+
name: "John",
8+
date: "1900-05-20",
9+
hobby: "coding and coding repeat",
10+
address: "No.1 Century Avenue, Shanghai",
11+
},
12+
{
13+
name: "Dickerson",
14+
date: "1910-06-20",
15+
hobby: "coding and coding repeat",
16+
address: "No.1 Century Avenue, Beijing",
17+
},
18+
{
19+
name: "Larsen",
20+
date: "2000-07-20",
21+
hobby: "coding and coding repeat",
22+
address: "No.1 Century Avenue, Chongqing",
23+
},
24+
{
25+
name: "Geneva",
26+
date: "2010-08-20",
27+
hobby: "coding and coding repeat",
28+
address: "No.1 Century Avenue, Xiamen",
29+
},
30+
{
31+
name: "Jami",
32+
date: "2020-09-20",
33+
hobby: "coding and coding repeat",
34+
address: "No.1 Century Avenue, Shenzhen",
35+
},
36+
];
37+
38+
const COLUMNS = [
39+
{
40+
field: "name",
41+
key: "a",
42+
title: "Name",
43+
align: "center",
44+
},
45+
{
46+
field: "date",
47+
key: "b",
48+
title: "Date",
49+
align: "left",
50+
},
51+
{
52+
field: "hobby",
53+
key: "c",
54+
title: "Hobby",
55+
align: "right",
56+
},
57+
{ field: "address", key: "d", title: "Address" },
58+
];
59+
60+
it("scroll method", () => {
61+
const wrapper = mount(veTable, {
62+
propsData: {
63+
columns: COLUMNS,
64+
tableData: TABLE_DATA,
65+
maxHeight: 50,
66+
},
67+
});
68+
69+
expect(0).toEqual(0);
70+
71+
// expect(wrapper.find(".ve-table-container").scrollTop).toBeGreaterThan(
72+
// 100,
73+
// );
74+
75+
// wrapper.vm.scroll({ top: 10 });
76+
77+
// expect(wrapper.find(".ve-table-container").scrollTop).toEqual(10);
78+
});
79+
});

0 commit comments

Comments
 (0)