Skip to content

Commit 5f290d9

Browse files
author
Kenneth Cheng
committed
revise readme
1 parent cc0695e commit 5f290d9

File tree

5 files changed

+99
-23
lines changed

5 files changed

+99
-23
lines changed

README.md

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ In your template
132132
| summary | Optional | String | Summary: 'sum', 'avg', 'max', 'min'. Default is null |
133133
| sort | Optional | Function | The custom function for sorting the column |
134134
| link | Optional | Function | The function to react to the alt-click on cell text |
135+
| is-link | Optional | Function | The function to identify it is a link |
135136
| to-text | Optional | Function | The function to convert from object value to edit-text |
136137
| to-value | Optional | Function | The function to convert from edit-text to object value |
138+
| placeholder | Optional | String | The custom text if the field is null |
137139

138140
@ - Function can return a promise
139141

@@ -153,6 +155,7 @@ In your template
153155
| datetick | unix timestamp | yyyy-mm-dd | left | valid date | none | Y |
154156
| datetimetick | unix timestamp | yyyy-mm-dd hh:mn | left | valid datetime | none | Y |
155157
| datetimesectick | unix timestamp | yyyy-mm-dd hh:mn:ss | left | valid datetimesec | none | Y |
158+
| action | string | null | center | none | none | Y |
156159

157160
## Hot Key List
158161

@@ -230,18 +233,20 @@ In your template
230233

231234
### Variable Component: vue-excel-editor
232235

233-
| Name | Type | Description |
234-
| :--- | :--- | :--- |
235-
| processing | Boolean | Component is busy or not |
236-
| pageTop | Number | The top row number of the current page |
237-
| pageSize | Number | The number of rows of each page |
238-
| fields | AOO | It contains the column spec create when mount |
239-
| filterColumn | Object | Contains the current filters, developer can access the filter string via this |
240-
| table | AOO | It contains the filtered records |
241-
| selected | Object | Contains all the selected rows, the key is row number and the value is internal $id |
242-
| selectedCount | Number | Number of rows are selected |
243-
| errmsg | Object | Contains all the validation error messages, the key is internal $id plus field name |
244-
| redo | AOA | The buffer of undo, it will be removed after undo or table changed |
236+
| Name | Type | Description |
237+
| :--- | :--- | :--- |
238+
| processing | Boolean | Component is busy or not |
239+
| pageTop | Number | The top row number of the current page |
240+
| pageSize | Number | The number of rows of each page |
241+
| fields | AOO | It contains the column spec create when mount |
242+
| filterColumn | Object | Contains the current filters, developer can access the filter string via this |
243+
| table | AOO | It contains the filtered records |
244+
| selected | Object | Contains all the selected rows, the key is row number and the value is internal $id |
245+
| selectedCount@ | Number | Number of rows are selected |
246+
| errmsg | Object | Contains all the validation error messages, the key is internal $id plus field name |
247+
| redo | AOA | The buffer of undo, it will be removed after undo or table changed |
248+
249+
@ - allow v-model binding
245250

246251
AOA = Array of Array, i.e. [[...], [...]]
247252
AOO = Array of Object, i.e. [{...}, {...}]
@@ -451,22 +456,31 @@ methods: {
451456
You may also want to watch the selected records count for displaying the action buttons. For example:
452457

453458
```html
459+
<vue-excel-editor v-model:selected-count="count">
460+
...
461+
</vue-excel-editor>
462+
454463
<button v-show="showDeleteAction"> Delete </button>
455464
<button v-show="showSendEmailInvitationAction"> Invite </button>
456465
<button v-show="showSendBirthdayGreetingAction"> Greeting </button>
457466
```
458467

459468
```js
469+
data () {
470+
return {
471+
count: 0
472+
}
473+
}
460474
computed: {
461475
showDeleteAction () {
462-
return this.$refs.grid.selectedCount > 0 // Show if any records selected
476+
return this.count > 0 // Show if any records selected
463477
},
464478
showSendEmailInvitationAction () {
465-
return this.$refs.grid.selectedCount === 1 // Show if single record is selected
479+
return this.count === 1 // Show if single record is selected
466480
},
467481
showSendBirthdayGreetingAction () {
468482
// Show only if any selected people birthday matched today
469-
if (this.$refs.grid.selectedCount > 0) {
483+
if (this.count > 0) {
470484
return this.$refs.grid.getSelectedRecords().filter(item => item.birth === today).length > 0
471485
else
472486
return false
@@ -732,18 +746,23 @@ Use this with care. The summary calculation eats resource, so it only calculates
732746
This is a nice feature in enterprise applications. Actually, I was learning from SAP UI. When the user holds the function key (Alt-key here) and move the mouse over the cell content, the text will show as a link. If user clicks on the link, your custom function will be triggered. The following example shows how to route to the user profile page by clicking on the name column cell.
733747
734748
```html
735-
<vue-excel-column field="name" label="Name" type="string" width="150px" :link="routeToUserFunc" />
749+
<vue-excel-column field="name" label="Name" type="string" width="150px" :link="routeToUserFunc" :is-link="showLinkOrString" />
736750
```
737751
738752
```js
739753
methods: {
740754
// Hold Alt Key and click on any name, program will route to the page "User Profile"
741755
routeToUserFunc (content, record) {
742756
this.$router.push(`/user/${record.user}`)
757+
},
758+
showLinkOrString(record) {
759+
return record.gender === 'M' // Only gender M show the link
743760
}
744761
}
745762
```
746763
764+
All links will be set as readonly
765+
747766
### Text/Value conversion
748767
749768
Sometimes displaying text and the store value will be different. In order to deal with this, you could use column properties to-text and to-value.
@@ -765,6 +784,54 @@ methods: {
765784
}
766785
```
767786
787+
### Badge
788+
789+
Sometimes we want to display the text in badge style.
790+
791+
```html
792+
<vue-excel-column field="user" label="User ID" type="badge" width="80px" :bg-color="badgeColor" />
793+
```
794+
795+
```js
796+
methods: {
797+
badgeColor (rec) {
798+
return 'blue'
799+
}
800+
}
801+
```
802+
803+
All badge will be set as readonly
804+
805+
### Action
806+
807+
Sometimes we want to display the list of actions for record processing, such as Edit/Remove.
808+
809+
```html
810+
<vue-excel-column field="do" label="Action" type="action" :options="['Edit', 'Remove']" width="100px" :change="doAction" placeholder="Action" />
811+
```
812+
813+
```js
814+
methods: {
815+
doAction (rec) {
816+
if (rec.do === 'Edit')
817+
// do Edit process
818+
else if (rec.do === 'Remove')
819+
// do Remove process
820+
}
821+
}
822+
```
823+
824+
All action will be set as non-readonly
825+
826+
### Password
827+
828+
For password editing:
829+
830+
```html
831+
<vue-excel-column type="password" field="pwd" label="Password" width="90px" />
832+
```
833+
834+
768835
### Localization
769836
770837
The developer may override the default values through localized-label prop.

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

src/VueExcelColumn.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
field: {type: String, default: 'dummy'},
99
label: {type: String, default: null},
1010
type: {type: String, default: 'string'},
11-
initStyle: {type: Object, default: null},
11+
initStyle: {type: [Object, Function], default: null},
1212
width: {type: String, default: '100px'},
1313
invisible: {type: Boolean, default: false},
1414
readonly: {type: Boolean, default: null},
@@ -21,6 +21,7 @@ export default {
2121
validate: {type: Function, default: null},
2222
change: {type: Function, default: null},
2323
link: {type: Function, default: null},
24+
isLink: {type: Function, default: null},
2425
format: {type: String, default: 'text'},
2526
cellClick: {type: Function, default: null},
2627
autoFillWidth: {type: Boolean, default: false},
@@ -115,7 +116,7 @@ export default {
115116
case 'password':
116117
return this.masking.repeat(val?.length || 0)
117118
case 'action':
118-
return this.placeholder || ''
119+
return ''
119120
case 'badge':
120121
if (this.bgcolor) {
121122
let bgcolor = this.bgcolor
@@ -234,7 +235,7 @@ export default {
234235
if (this.textAlign) style.textAlign = this.textAlign
235236
// if (this.readonly && this.$parent.readonlyStyle) style = Object.assign(style, this.$parent.readonlyStyle)
236237
237-
this._autocomplete = self.autocomplete
238+
this._autocomplete = self.autocomplete || self.type === 'action'
238239
this._readonly = self.readonly
239240
240241
this.$parent.registerColumn({
@@ -247,6 +248,7 @@ export default {
247248
validate: validate,
248249
change: this.change,
249250
link: this.link,
251+
isLink: this.isLink || (this.link ? () => true : null),
250252
sort: this.sort,
251253
252254
keyField: this.keyField,
@@ -267,6 +269,8 @@ export default {
267269
initStyle: style,
268270
invisible: this.invisible,
269271
get readonly () {
272+
if (self.link) return true
273+
if (self.type === 'action') return false
270274
return self._readonly === null ? self.$parent.readonly : self._readonly
271275
},
272276
set readonly (val) {
@@ -278,7 +282,11 @@ export default {
278282
masking: this.masking,
279283
format: this._format || this.format,
280284
toValue: this.toValue,
281-
toText: this.toText,
285+
toText: (...arg) => {
286+
const result = this.toText(...arg)
287+
if (this.placeholder && result === '') return this.placeholder
288+
return result
289+
},
282290
register: this.register,
283291
placeholder: this.placeholder,
284292
cellClick: this.cellClick,

src/VueExcelEditor.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
:class="{
116116
readonly: item.readonly,
117117
error: errmsg[`id-${record.$id}-${item.name}`],
118-
link: item.link && item.toText(record[item.name]),
118+
link: item.link && item.isLink && item.isLink(record),
119119
select: item.options,
120120
datepick: item.type == 'date',
121121
stickyColumn: item.sticky
@@ -918,6 +918,7 @@ export default defineComponent({
918918
},
919919
renderColumnCellStyle (field, record) {
920920
let result = field.initStyle
921+
if (typeof result === 'function') result = result(record, field)
921922
if (field.readonly) result = Object.assign(result, this.readonlyStyle)
922923
if (field.left) result.left = field.left
923924
if (record && field.color)

0 commit comments

Comments
 (0)