Skip to content

Commit fc32ccd

Browse files
committed
Some refactor
1 parent a882383 commit fc32ccd

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

lib/components/table.vue

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,46 @@
44
:class="tableClass"
55
>
66
<thead :class="headClass">
7-
<tr>
8-
<th v-for="(field,key) in fields"
9-
@click.stop.prevent="headClicked($event,field,key)"
10-
@keydown.enter.stop.prevent="headClicked($event,field,key)"
11-
@keydown.space.stop.prevent="headClicked($event,field,key)"
12-
:key="key"
13-
:class="fieldClass(field,key)"
14-
:style="field.thStyle || {}"
15-
:aria-label="field.sortable ? ((localSortDesc && localSortBy === key) ? labelSortAsc : labelSortDesc) : null"
16-
:aria-sort="(field.sortable && localSortBy === key) ? (localSortDesc ? 'descending' : 'ascending') : null"
17-
:tabindex="field.sortable?'0':null"
18-
>
19-
<slot :name="'HEAD_'+key" :label="field.label" :column="key" :field="field">
7+
<tr>
8+
<th v-for="(field,key) in fields"
9+
@click.stop.prevent="headClicked($event,field,key)"
10+
@keydown.enter.stop.prevent="headClicked($event,field,key)"
11+
@keydown.space.stop.prevent="headClicked($event,field,key)"
12+
:key="key"
13+
:class="fieldClass(field,key)"
14+
:style="field.thStyle || {}"
15+
:aria-label="field.sortable ? ((localSortDesc && localSortBy === key) ? labelSortAsc : labelSortDesc) : null"
16+
:aria-sort="(field.sortable && localSortBy === key) ? (localSortDesc ? 'descending' : 'ascending') : null"
17+
:tabindex="field.sortable?'0':null"
18+
>
19+
<slot :name="'HEAD_'+key" :label="field.label" :column="key" :field="field">
2020
<div v-html="field.label"></div>
21-
</slot>
22-
</th>
23-
</tr>
21+
</slot>
22+
</th>
23+
</tr>
2424
</thead>
2525
<tfoot v-if="footClone" :class="footClass">
26-
<tr>
27-
<th v-for="(field,key) in fields"
28-
@click.stop.prevent="headClicked($event,field,key)"
29-
@keydown.enter.stop.prevent="headClicked($event,field,key)"
30-
@keydown.space.stop.prevent="headClicked($event,field,key)"
31-
:key="key"
32-
:class="fieldClass(field,key)"
33-
:style="field.thStyle || {}"
34-
:aria-label="field.sortable ? ((localSortDesc && localSortBy === key) ? labelSortAsc : labelSortDesc) : null"
35-
:aria-sort="(field.sortable && localSortBy === key) ? (localSortDesc ? 'descending' : 'ascending') : null"
36-
:tabindex="field.sortable?'0':null"
37-
>
38-
<slot v-if="$scopedSlots['FOOT_'+key]" :name="'FOOT_'+key" :label="field.label" :column="key" :field="field">
26+
<tr>
27+
<th v-for="(field,key) in fields"
28+
@click.stop.prevent="headClicked($event,field,key)"
29+
@keydown.enter.stop.prevent="headClicked($event,field,key)"
30+
@keydown.space.stop.prevent="headClicked($event,field,key)"
31+
:key="key"
32+
:class="fieldClass(field,key)"
33+
:style="field.thStyle || {}"
34+
:aria-label="field.sortable ? ((localSortDesc && localSortBy === key) ? labelSortAsc : labelSortDesc) : null"
35+
:aria-sort="(field.sortable && localSortBy === key) ? (localSortDesc ? 'descending' : 'ascending') : null"
36+
:tabindex="field.sortable?'0':null"
37+
>
38+
<slot v-if="$scopedSlots['FOOT_'+key]" :name="'FOOT_'+key" :label="field.label" :column="key"
39+
:field="field">
3940
<div v-html="field.label"></div>
40-
</slot>
41-
<slot v-else :name="'HEAD_'+key" :label="field.label" :column="key" :field="field">
41+
</slot>
42+
<slot v-else :name="'HEAD_'+key" :label="field.label" :column="key" :field="field">
4243
<div v-html="field.label"></div>
43-
</slot>
44-
</th>
45-
</tr>
44+
</slot>
45+
</th>
46+
</tr>
4647
</tfoot>
4748
<tbody>
4849
<tr v-for="(item,index) in _items"
@@ -53,7 +54,7 @@
5354
>
5455
<template v-for="(field,key) in fields">
5556
<td v-if="hasFormatter(field)" :key="key" :class="tdClass(field, item, key)"
56-
v-html="callFormatter(field, item, key)">
57+
v-html="callFormatter(item, key, field)">
5758
</td>
5859
<td v-else :class="tdClass(field, item, key)" :key="key">
5960
<slot :name="key" :value="item[key]" :item="item" :index="index">{{item[key]}}</slot>
@@ -81,7 +82,7 @@
8182
<script>
8283
import { warn } from '../utils';
8384
import { keys } from '../utils/object.js';
84-
import {listenOnRootMixin} from '../mixins';
85+
import { listenOnRootMixin } from '../mixins';
8586
8687
const toString = v => {
8788
if (!v) {
@@ -135,7 +136,7 @@
135136
default() {
136137
if (this && this.itemsProvider) {
137138
// Deprecate itemsProvider
138-
warn("b-table: prop 'items-provider' has been deprecated. Pass a function to 'items' instead");
139+
warn('b-table: prop \'items-provider\' has been deprecated. Pass a function to \'items\' instead');
139140
return this.itemsProvider;
140141
}
141142
return [];
@@ -482,13 +483,7 @@
482483
return;
483484
}
484485
let sortChanged = false;
485-
if (!field.sortable) {
486-
if (this.localSortBy) {
487-
this.localSortBy = null;
488-
this.localSortDesc = false;
489-
sortChanged = true;
490-
}
491-
} else {
486+
if (field.sortable) {
492487
if (key === this.localSortBy) {
493488
// Change sorting direction on current column
494489
this.localSortDesc = !this.localSortDesc;
@@ -498,7 +493,12 @@
498493
this.localSortDesc = false;
499494
}
500495
sortChanged = true;
496+
} else if (this.localSortBy) {
497+
this.localSortBy = null;
498+
this.localSortDesc = false;
499+
sortChanged = true;
501500
}
501+
502502
this.$emit('head-clicked', key, field);
503503
if (sortChanged) {
504504
// Sorting parameters changed
@@ -544,7 +544,7 @@
544544
hasFormatter(field) {
545545
return field.formatter && ((typeof (field.formatter) === 'function') || (typeof (field.formatter) === 'string'));
546546
},
547-
callFormatter(field, item, key) {
547+
callFormatter(item, key, field) {
548548
if (field.formatter && (typeof (field.formatter) === 'function'))
549549
return field.formatter(item[key]);
550550

0 commit comments

Comments
 (0)