Skip to content

Commit f429734

Browse files
author
Kenneth Cheng
committed
autoFillWidth prop
1 parent 0925b27 commit f429734

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ In your template
116116
| sticky | Optional | Boolean | Fixed column at left of the table, no response on horizontal scrolling |
117117
| invisible | Optional | Boolean | Column visibility, default is false |
118118
| width | Optional | String | Specified column width, default is '100px' |
119+
| autoFillWidth | Optional | Boolean | Extend the width of this column to fill the editor width, default is false |
119120
| change | Optional | Function@ | The function to be triggered when the data of this column changed |
120121
| validate | Optional | Function | The function to validate and return the error message |
121122
| key-field | Optional | Boolean | Specified the key field which is included in keys parameter in @update event |

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.11",
5+
"version": "1.0.12",
66
"main": "src/main.js",
77
"dependencies": {
88
"@vuepic/vue-datepicker": "^3.3.0",

src/VueExcelColumn.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default {
2020
validate: {type: Function, default: null},
2121
change: {type: Function, default: null},
2222
link: {type: Function, default: null},
23+
autoFillWidth: {type: Boolean, default: false},
2324
2425
allowKeys: {type: [Array, Function], default () {return null}},
2526
mandatory: {type: String, default: ''},
@@ -210,6 +211,7 @@ export default {
210211
label: this.label === null ? this.field : this.label,
211212
type: this.type,
212213
width: this.width,
214+
autoFillWidth: this.autoFillWidth,
213215
214216
validate: validate,
215217
change: this.change,

src/VueExcelEditor.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="vue-excel-editor" :style="{display: 'inline-block', 'max-width': width}">
2+
<div ref="editor" class="vue-excel-editor" :style="{display: 'inline-block', width}">
33
<div class="component-content">
44
<!-- No record -->
55
<div v-if="localizedLabel.noRecordIndicator && pagingTable.length == 0" class="norecord" :style="{bottom: noFooter? '12px' : '37px'}">
@@ -23,7 +23,7 @@
2323
ondragover="event.preventDefault(); event.dataTransfer.dropEffect = 'none'">
2424
<colgroup>
2525
<col v-if="!noNumCol" style="width:40px">
26-
<col v-for="(item, p) in fields" v-show="!item.invisible" :key="p" :style="{width: item.width}">
26+
<col v-for="(item, p) in fields" v-show="!item.invisible" :key="p" :style="{width: item.width, 'min-width': item.minWidth || item.width}">
2727
<col v-if="vScroller.buttonHeight < vScroller.height" style="width:12px">
2828
</colgroup>
2929
<thead class="center-text">
@@ -569,6 +569,7 @@ export default {
569569
window.removeEventListener('wheel', this.mousewheel)
570570
},
571571
mounted () {
572+
this.editor = this.$refs.editor
572573
this.tableContent = this.$refs.tableContent
573574
this.systable = this.$refs.systable
574575
this.colgroupTr = this.systable.children[0]
@@ -1034,6 +1035,20 @@ export default {
10341035
// this.refresh()
10351036
},
10361037
1038+
columnFillWidth () {
1039+
if (this.table.length === 0) return
1040+
if (!this.editor) return
1041+
const doFields = this.fields.filter(f => f.autoFillWidth)
1042+
const count = doFields.length
1043+
if (!count) return
1044+
1045+
const fullWidth = this.editor.getBoundingClientRect().width
1046+
const viewWidth = this.fields.filter(f => !f.invisible).reduce((c, f) => c - -f.width.replace(/px$/, ''), 0) + 40
1047+
const fillWidth = viewWidth - fullWidth + 2
1048+
if (fillWidth)
1049+
doFields.forEach(f => f.minWidth = (f.width.replace(/px$/, '') - fillWidth / count) + 'px')
1050+
},
1051+
10371052
/* *** Date Picker *********************************************************************************
10381053
*/
10391054
showDatePickerDiv () {
@@ -1251,7 +1266,7 @@ export default {
12511266
return false
12521267
},
12531268
winResize () {
1254-
this.lazy(this.refreshPageSize, 200)
1269+
this.lazy(this.refreshPageSize, 500)
12551270
},
12561271
winPaste (e) {
12571272
if (e.target.tagName !== 'TEXTAREA') return
@@ -1683,6 +1698,7 @@ export default {
16831698
h = Math.min(24 * (this.table.length - this.pageTop) + offset, h)
16841699
this.systable.parentNode.style.height = h + 'px'
16851700
}
1701+
this.columnFillWidth()
16861702
setTimeout(this.calVScroll)
16871703
},
16881704
firstPage (e) {

0 commit comments

Comments
 (0)