Skip to content

Commit 93b52a8

Browse files
author
Kenneth Cheng
committed
Fix noNumCol UI problem, add 3-way sorting
1 parent c43a032 commit 93b52a8

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ In your template
103103
| disable-panel-setting | Optional | Boolean | Hide the setting panel |
104104
| disable-panel-filter | Optional | Boolean | Hide the filter panel |
105105
| no-mouse-scroll | Optional | Boolean | Disable the vertical scrolling by mouse |
106+
| no-sorting | Optional | Boolean | Disable the sorting |
107+
| no-mass-update | Optional | Boolean | Disable mass update of selected records |
106108

107109
### Prop Component: vue-excel-column
108110

@@ -136,6 +138,7 @@ In your template
136138
| to-text | Optional | Function | The function to convert from object value to edit-text |
137139
| to-value | Optional | Function | The function to convert from edit-text to object value |
138140
| placeholder | Optional | String | The custom text if the field is null |
141+
| no-sorting | Optional | Boolean | Disable the sorting of the column |
139142

140143
@ - Function can return a promise
141144

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vue3-excel-editor",
33
"email": "apple.6502@gmail.com",
44
"description": "Vue3 plugin for displaying and editing the array-of-object in Excel style",
5-
"version": "1.0.48",
5+
"version": "1.0.49",
66
"main": "src/main.js",
77
"dependencies": {
88
"@vuepic/vue-datepicker": "^3.3.0",

src/VueExcelEditor.vue

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</tbody>
133133
<tfoot>
134134
<tr v-show="pagingTable.length && summaryRow">
135-
<td class="row-summary first-col">&nbsp;</td>
135+
<td class="row-summary first-col" :class="{'hide': noNumCol}">&nbsp;</td>
136136
<td v-for="(field, p) in fields"
137137
v-show="!field.invisible"
138138
class="row-summary"
@@ -212,8 +212,8 @@
212212
<!-- Footer -->
213213
<div ref="footer" class="footer center-text" :class="{hide: noFooter}" style="position:relative" @mousedown="ftMouseDown">
214214
<div ref="hScroll" class="h-scroll" @mousedown="sbMouseDown" />
215-
<span class="left-block"></span>
216-
<span v-show="!noPaging" style="position: absolute; left: 46px">
215+
<span class="left-block" :class="{'hide': noNumCol}"></span>
216+
<span v-show="!noPaging" class="footer-left">
217217
<span v-html="localizedLabel.footerLeft(pageTop + 1, pageBottom, table.length)"></span>
218218
</span>
219219
<span v-show="!noPaging && pageBottom - pageTop < table.length">
@@ -248,7 +248,7 @@
248248
</a>
249249
</template>
250250
</span>
251-
<span style="position: absolute; right: 6px">
251+
<span class="footer-right">
252252
<a :class="{disabled: !showSelectedOnly && selectedCount <= 1}" @mousedown="toggleSelectView">
253253
<span v-html="localizedLabel.footerRight.selected" />
254254
<span :style="{color: selectedCount>0 ? 'red': 'inherit'}">{{ selectedCount }}</span>
@@ -330,6 +330,7 @@ export default defineComponent({
330330
noFinding: {type: Boolean, default: false},
331331
noFindingNext: {type: Boolean, default: false},
332332
noSorting: {type: Boolean, default: false},
333+
noMassUpdate: {type: Boolean, default: false},
333334
filterRow: {type: Boolean, default: false},
334335
freeSelect: {type: Boolean, default: false},
335336
noFooter: {type: Boolean, default: false},
@@ -485,6 +486,10 @@ export default defineComponent({
485486
return dataset
486487
},
487488
computed: {
489+
numColWidth () {
490+
if (this.noNumCol) return 0
491+
else return 40
492+
},
488493
selectedCount: {
489494
get () {
490495
return this._selectedCount
@@ -1098,12 +1103,15 @@ export default defineComponent({
10981103
const count = doFields.length
10991104
if (!count) return
11001105
1101-
const fullWidth = this.editor.getBoundingClientRect().width
1102-
const viewWidth = this.fields.filter(f => !f.invisible).reduce((c, f) => c - -f.width.replace(/px$/, ''), 0)
1103-
+ (this.noNumCol ? 0 : 40)
1104-
const fillWidth = viewWidth - fullWidth + 2
1105-
if (fillWidth)
1106-
doFields.forEach(f => f.width = (f.width.replace(/px$/, '') - fillWidth / count) + 'px')
1106+
setTimeout(() => {
1107+
const fullWidth = this.editor.getBoundingClientRect().width
1108+
let viewWidth = this.fields.filter(f => !f.invisible).reduce((c, f) => c - -f.width.replace(/px$/, ''), 0)
1109+
viewWidth += this.numColWidth
1110+
if (this.tableContent.scrollHeight > this.tableContent.clientHeight) viewWidth += 13
1111+
const fillWidth = viewWidth - fullWidth + 2
1112+
if (fillWidth)
1113+
doFields.forEach(f => f.width = (f.width.replace(/px$/, '') - fillWidth / count) + 'px')
1114+
})
11071115
},
11081116
11091117
/* *** Date Picker *********************************************************************************
@@ -1157,7 +1165,7 @@ export default defineComponent({
11571165
calVScroll () {
11581166
let d = this.labelTr.getBoundingClientRect().height
11591167
if (this.filterRow) d += 29
1160-
this.vScroller.top = d
1168+
this.vScroller.top = d - 1
11611169
if (!this.noFooter) d += 25
11621170
if (this.summaryRow) d += 27
11631171
const fullHeight = this.$el.getBoundingClientRect().height
@@ -1239,7 +1247,7 @@ export default defineComponent({
12391247
*/
12401248
ftMouseDown (e) {
12411249
const footerRect = this.footer.getBoundingClientRect()
1242-
const ratio = (e.x - footerRect.left - 40) / (footerRect.width - 40)
1250+
const ratio = (e.x - footerRect.left - this.numColWidth) / (footerRect.width - this.numColWidth)
12431251
const fullWidth = this.systable.getBoundingClientRect().width
12441252
const viewWidth = this.tableContent.getBoundingClientRect().width
12451253
this.tableContent.scrollTo(fullWidth * ratio - viewWidth / 2, this.tableContent.scrollTop)
@@ -1248,7 +1256,7 @@ export default defineComponent({
12481256
e.stopPropagation()
12491257
if (!this.hScroller.mouseX) {
12501258
const sleft = this.$refs.hScroll.getBoundingClientRect().left
1251-
const fleft = this.footer.getBoundingClientRect().left + 40
1259+
const fleft = this.footer.getBoundingClientRect().left + this.numColWidth
12521260
this.hScroller.left = sleft - fleft
12531261
this.hScroller.mouseX = e.clientX
12541262
window.addEventListener('mousemove', this.sbMouseMove)
@@ -1707,8 +1715,10 @@ export default defineComponent({
17071715
e.preventDefault()
17081716
if (this.sortPos === colPos && this.sortDir > 0)
17091717
this.sort(-1, colPos)
1710-
else
1718+
else if (this.sortDir === 0)
17111719
this.sort(1, colPos)
1720+
else
1721+
this.sort(0, colPos)
17121722
}
17131723
},
17141724
completeHeaderChange (e) {
@@ -1738,11 +1748,17 @@ export default defineComponent({
17381748
return String(a).localeCompare(String(b))
17391749
}
17401750
}
1741-
this.modelValue.sort((a, b) => {
1742-
if (field.sort) return field.sort(a, b) * -n
1743-
else return sorting(a[name], b[name]) * -n
1744-
})
1745-
this.sortPos = colPos
1751+
if (n === 0) {
1752+
this.modelValue.sort((a, b) => a.$id > b.$id ? 1 : -1)
1753+
this.sortPos = 0
1754+
}
1755+
else {
1756+
this.modelValue.sort((a, b) => {
1757+
if (field.sort) return field.sort(a, b) * -n
1758+
else return sorting(a[name], b[name]) * -n
1759+
})
1760+
this.sortPos = colPos
1761+
}
17461762
this.sortDir = n
17471763
this.refresh()
17481764
this.processing = false
@@ -1758,7 +1774,7 @@ export default defineComponent({
17581774
this.hScroller.tableUnseenWidth = fullWidth - viewWidth
17591775
this.$refs.hScroll.style.width = (100 * viewWidth / fullWidth) + '%'
17601776
const scrollerWidth = this.$refs.hScroll.getBoundingClientRect().width
1761-
this.hScroller.scrollerUnseenWidth = this.footer.getBoundingClientRect().width - 40 - scrollerWidth
1777+
this.hScroller.scrollerUnseenWidth = this.footer.getBoundingClientRect().width - this.numColWidth - scrollerWidth
17621778
}
17631779
if (!this.noPaging) {
17641780
const offset = this.summaryRow ? 60 : 35
@@ -2297,7 +2313,7 @@ export default defineComponent({
22972313
this.currentField = this.fields[colPos]
22982314
this.currentCell = row.children[colPos + 1]
22992315
this.currentRecord = this.table[this.pageTop + rowPos]
2300-
this.$emit('cell-click', {rowPos, colPos})
2316+
this.$emit('cell-click', {rowPos, colPos}, this.currentCell.textContent, this.currentRecord, this.currentField, this)
23012317
if (typeof this.currentField.cellClick === 'function')
23022318
this.currentField.cellClick(this.currentCell.textContent, this.currentRecord, rowPos, colPos, this.currentField, this)
23032319
if (this.currentField && this.currentField.link /* && e.altKey */ && this.currentCell.textContent)
@@ -2517,7 +2533,7 @@ export default defineComponent({
25172533
let field = this.currentField
25182534
if (typeof colPos !== 'undefined') field = this.fields[colPos]
25192535
if (typeof recPos === 'undefined') recPos = this.pageTop + this.currentRowPos
2520-
if (typeof this.selected[recPos] !== 'undefined')
2536+
if (!this.noMassUpdate && typeof this.selected[recPos] !== 'undefined')
25212537
this.updateSelectedRows(field, setText)
25222538
else
25232539
this.updateCell(recPos, field, field.toValue(setText, this.table[recPos], field))
@@ -2998,10 +3014,8 @@ input:focus, input:active:focus, input.active:focus {
29983014
border: 0;
29993015
border-collapse: separate;
30003016
border-spacing: 0;
3001-
/*
30023017
margin-bottom: -1px;
30033018
border-bottom: 1px solid lightgray;
3004-
*/
30053019
}
30063020
.systable .last-col {
30073021
width: 12px;
@@ -3200,12 +3214,21 @@ input:focus, input:active:focus, input.active:focus {
32003214
background-color: #e9ecef;
32013215
border-right: 1px solid lightgray;
32023216
}
3217+
.footer-left {
3218+
position: absolute;
3219+
left: calc(v-bind(numColWidth)*1px);
3220+
margin-left: 6px;
3221+
}
3222+
.footer-right {
3223+
position: absolute;
3224+
right: 6px;
3225+
}
32033226
.h-scroll {
32043227
z-index: -1;
32053228
position: absolute;
32063229
background-color: #f4f6f9;
32073230
height: 25px;
3208-
margin-left: 40px;
3231+
margin-left: calc(v-bind(numColWidth)*1px);
32093232
width: 65%;
32103233
cursor: pointer;
32113234
}

0 commit comments

Comments
 (0)