Skip to content

Commit 37c9ada

Browse files
author
Kenneth Cheng
committed
implement hide-duplicate
1 parent 5f290d9 commit 37c9ada

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ methods: {
761761
}
762762
```
763763
764-
All links will be set as readonly
764+
All links will be set as readonly by default.
765765
766766
### Text/Value conversion
767767
@@ -800,7 +800,7 @@ methods: {
800800
}
801801
```
802802
803-
All badge will be set as readonly
803+
All badge will be set as readonly by default.
804804
805805
### Action
806806
@@ -821,7 +821,8 @@ methods: {
821821
}
822822
```
823823
824-
All action will be set as non-readonly
824+
All action will be set as non-readonly to make it selectable. The component will assign a to-text function to return empty string.
825+
If you want to show a static text in cell, you could use placeholder prop.
825826
826827
### Password
827828
@@ -831,6 +832,25 @@ For password editing:
831832
<vue-excel-column type="password" field="pwd" label="Password" width="90px" />
832833
```
833834
835+
### Hide Duplication
836+
837+
If a column set to hide-duplicaiton, the component will compare the cell content with the above content and hide it by setting
838+
to transparent color and remove the border-top. It also affects the next column which also set to hide-duplication. Here is an example:
839+
840+
```html
841+
<vue-excel-editor v-model="jsondata" filter-row>
842+
<vue-excel-column type="map" field="gender" width="80px" label="Gender" :options="{M: 'Male', F: 'Female'}" hide-duplicate />
843+
<vue-excel-column type="number" field="age" width="60px" label="Age" summary="avg" hide-duplicate />
844+
<vue-excel-column type="badge" field="user" width="75px" label="User" :bgcolor="badgeColor" />
845+
<vue-excel-column type="string" field="name" width="150px" label="Name" :link="linkClick" :is-link="isLink" />
846+
<vue-excel-column type="string" field="phone" width="160px" label="Contact" />
847+
<vue-excel-column type="password" field="pwd" width="90px" label="Password" />
848+
<vue-excel-column type="date" field="birth" width="115px" label="Date Of Birth" />
849+
<vue-excel-column type="action" field="action" width="75px" label="#" :options="['Edit', 'Remove']" :change="doAction" placeholder="Action" />
850+
</vue-excel-editor>
851+
```
852+
853+
![Hide Duplication](https://i.imgur.com/HCFyEEp.png "Hide Duplication")
834854
835855
### Localization
836856

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

src/VueExcelColumn.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
format: {type: String, default: 'text'},
2626
cellClick: {type: Function, default: null},
2727
autoFillWidth: {type: Boolean, default: false},
28+
hideDuplicate: {type: Boolean, default: false},
2829
2930
allowKeys: {type: [Array, Function], default () {return null}},
3031
mandatory: {type: String, default: ''},
@@ -292,7 +293,8 @@ export default {
292293
cellClick: this.cellClick,
293294
listByClick: this.listByClick || this._listByClick,
294295
color: this.color || this._color,
295-
bgcolor: this.bgcolor || this._bgcolor
296+
bgcolor: this.bgcolor || this._bgcolor,
297+
hideDuplicate: this.hideDuplicate
296298
})
297299
}
298300
}

src/VueExcelEditor.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
link: item.link && item.isLink && item.isLink(record),
119119
select: item.options,
120120
datepick: item.type == 'date',
121-
stickyColumn: item.sticky
121+
stickyColumn: item.sticky,
122+
hideDuplicate: item.hideDuplicate && rowPos > 0 && isSameSinceLeft(p, record, pagingTable[rowPos-1])
122123
}"
123124
:key="p"
124125
:style="Object.assign(cellStyle(record, item), renderColumnCellStyle(item, record))"
@@ -630,6 +631,15 @@ export default defineComponent({
630631
}
631632
},
632633
methods: {
634+
isSameSinceLeft(p, rec1, rec2) {
635+
for(let i=0; i<=p; i++) {
636+
if (!this.fields[i].invisible && this.fields[i].hideDuplicate) {
637+
const name = this.fields[i].name
638+
if (rec1[name] !== rec2[name]) return false
639+
}
640+
}
641+
return true
642+
},
633643
componentTabInto (e) {
634644
if (e.keyCode === 9) {
635645
if (!this.moveInputSquare(this.currentRowPos, this.currentColPos))
@@ -2387,6 +2397,7 @@ export default defineComponent({
23872397
this.labelTr.children[this.currentColPos + 1].classList.remove('focus')
23882398
if (this.currentRowPos >= 0 && this.currentRowPos < this.pagingTable.length)
23892399
this.recordBody.children[this.currentRowPos].children[0].classList.remove('focus')
2400+
this.lastCell?.classList.remove('focus')
23902401
23912402
// Off the textarea when moving, write to value if changed
23922403
if (this.inputBoxShow) this.inputBoxShow = 0
@@ -2426,6 +2437,8 @@ export default defineComponent({
24262437
this.currentRecord = this.table[top + rowPos]
24272438
24282439
this.$emit('cell-focus', {rowPos, colPos, cell, record: this.currentRecord})
2440+
this.currentCell.classList.add('focus')
2441+
this.lastCell = this.currentCell
24292442
24302443
// Off all editors
24312444
if (this.showDatePicker) this.showDatePicker = false
@@ -2492,6 +2505,7 @@ export default defineComponent({
24922505
this.recordBody.children[this.currentRowPos].children[0].classList.remove('focus')
24932506
this.labelTr.children[this.currentColPos + 1].classList.remove('focus')
24942507
}
2508+
this.lastCell?.classList.remove('focus')
24952509
},
24962510
inputBoxComplete () {
24972511
if (this.inputBoxChanged) {
@@ -3010,11 +3024,11 @@ input:focus, input:active:focus, input.active:focus {
30103024
background-size: 8px 8px !important;
30113025
background-position: right 0px top 0px !important;
30123026
}
3013-
.systable tbody tr:not(:last-child) td {
3014-
border-bottom: 1px solid lightgray;
3027+
.systable tbody tr:not(:first-child) td {
3028+
border-top: 1px solid lightgray;
30153029
}
3016-
.systable tbody tr:last-child td {
3017-
border-bottom: 1px solid transparent;
3030+
.systable tbody tr:first-child td {
3031+
border-top: 1px solid transparent;
30183032
}
30193033
.systable td:not(:last-child) {
30203034
border-right: 1px solid lightgray;
@@ -3363,4 +3377,9 @@ a:disabled {
33633377
left: 50%;
33643378
transform: translate(-50%, 0%);
33653379
}
3380+
td.hideDuplicate:not(.focus) {
3381+
border-top: 1px solid transparent !important;
3382+
color: transparent;
3383+
text-shadow: none;
3384+
}
33663385
</style>

0 commit comments

Comments
 (0)