Skip to content

call sortChange on th click #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/style/ve-table.less
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
height: 16px;
margin-left: 5px;
color: @ve-table-sort-icon-default-color;
cursor: pointer;
pointer-events: none;
.ve-table-sort-icon {
position: absolute;
display: block;
Expand All @@ -108,6 +108,10 @@
}
}

&.ve-table-sortable-column {
cursor: pointer;
}

/* filter */
.ve-table-filter {
display: inline-block;
Expand Down
24 changes: 21 additions & 3 deletions packages/ve-table/src/header/header-th.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ export default {
}
}

return result;
},
// is sortable column
isSortableCloumn() {
let result = false;

const { sortColumns, groupColumnItem } = this;
const currentField = groupColumnItem.field;

if (Object.keys(sortColumns).includes(currentField)) {
result = true;
}

return result;
},
},
Expand All @@ -183,6 +196,7 @@ export default {
[clsName("first-right-fixed-column")]:
this.isfirstRightFixedColumn,
[clsName("last-column")]: this.isLastCloumn,
[clsName("sortable-column")]: this.isSortableCloumn,
};

const {
Expand Down Expand Up @@ -378,9 +392,6 @@ export default {

const props = {
class: clsName("sort"),
on: {
click: () => this.sortChange(),
},
};

result = (
Expand Down Expand Up @@ -592,6 +603,13 @@ export default {
const events = {
click: (e) => {
this.cellClick(e, click);

if (
this.isSortableCloumn &&
e.target instanceof HTMLTableCellElement
) {
this.sortChange();
}
},
dblclick: (e) => {
this.cellDblclick(e, dblclick);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ exports[`veTable header sort render multiple field sort 1`] = `
<thead class="ve-table-fixed-header ve-table-header">
<tr class="ve-table-header-tr">
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: left; top: 0px;">Name</th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Age<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Weight(kg)<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top active"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-sortable-column" style="text-align: center; top: 0px;">Age<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-sortable-column" style="text-align: center; top: 0px;">Weight(kg)<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top active"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Hobby</th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-last-column" style="text-align: left; top: 0px;">Address</th>
</tr>
Expand Down Expand Up @@ -96,8 +96,8 @@ exports[`veTable header sort render single field sort 1`] = `
<thead class="ve-table-fixed-header ve-table-header">
<tr class="ve-table-header-tr">
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: left; top: 0px;">Name</th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Age<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Weight(kg)<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top active"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-sortable-column" style="text-align: center; top: 0px;">Age<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-sortable-column" style="text-align: center; top: 0px;">Weight(kg)<span class="ve-table-sort"><i class="ve-icon iconfont-vet icon-vet-sort-top-arrow ve-table-sort-icon ve-table-sort-icon-top active"></i><i class="ve-icon iconfont-vet icon-vet-sort-bottom-arrow ve-table-sort-icon ve-table-sort-icon-bottom"></i></span></th>
<th rowspan="1" colspan="1" class="ve-table-header-th" style="text-align: center; top: 0px;">Hobby</th>
<th rowspan="1" colspan="1" class="ve-table-header-th ve-table-last-column" style="text-align: left; top: 0px;">Address</th>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/specs/ve-table-header-sort.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe("veTable header sort", () => {
.exists(),
).toBe(true);

thEls.at(1).find(".ve-table-sort").trigger("click");
thEls.at(1).find(".ve-table-sortable-column").trigger("click");

await later();

Expand Down Expand Up @@ -361,7 +361,7 @@ describe("veTable header sort", () => {
.exists(),
).toBe(true);

thEls.at(1).find(".ve-table-sort").trigger("click");
thEls.at(1).find(".ve-table-sortable-column").trigger("click");

await later();

Expand Down Expand Up @@ -425,7 +425,7 @@ describe("veTable header sort", () => {

const thEls = wrapper.findAll(".ve-table-header-tr th");

thEls.at(1).find(".ve-table-sort").trigger("click");
thEls.at(1).find(".ve-table-sortable-column").trigger("click");

await later();

Expand All @@ -434,7 +434,7 @@ describe("veTable header sort", () => {
weight: "",
});

thEls.at(1).find(".ve-table-sort").trigger("click");
thEls.at(1).find(".ve-table-sortable-column").trigger("click");

await later();

Expand Down