Skip to content

Commit dc9c4cf

Browse files
committed
checkbox table in-built
1 parent cb87d1f commit dc9c4cf

File tree

9 files changed

+220
-48
lines changed

9 files changed

+220
-48
lines changed

.gitignore

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
.DS_Store
22
npm-debug.log
33
node_modules/
4-
.idea/
5-
/demos/demo1/dist/
6-
/demos/demo1/package.json
7-
/demos/demo1/webpack.config.js
8-
/demos/demo2/dist/
9-
/demos/demo2/package.json
10-
/demos/demo2/webpack.config.js
11-
/test/unit/coverage/
12-

README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Some example recipes for inspiration
3737
- [Sort Options](#sort-options)
3838
- [Pagination Options](#pagination-options)
3939
- [Search Options](#search-options)
40+
- [Checkbox Table](#checkbox-table)
4041
- [Grouped Row Options](#grouped-row-options)
4142
- [Style/Theme](#styletheme)
4243
- [Column Options](#column-options)
@@ -474,18 +475,36 @@ data(){
474475
}
475476
```
476477

478+
#### Checkbox Table
479+
Creating table with selectable rows (checkboxes) is easier than ever.
480+
![Checkbox Screenshot](README/images/vgt-table.checkbox.png)
481+
482+
##### selectOptions `Object`
483+
Object containing select options
484+
```html
485+
<vue-good-table
486+
@on-select-all="allSelected"
487+
@on-row-click="rowSelected"
488+
:columns="columns"
489+
:rows="rows"
490+
:select-options="{
491+
enabled: true
492+
}">
493+
```
494+
Check out [a working example](https://jsfiddle.net/aks9800/keLjcssn/) for details
495+
496+
477497
#### Grouped Row Options
478498
---
479499
Sometimes you have a hierarchy in table and you want to group rows under subheadings, vue-good-table allows you to do that as well. Following properties relate to row grouping
480500

481501
##### groupOptions `Object`
482502
Object containing group related options.
483503
```html
484-
<input type="text" v-model="searchTerm" >
485504
<vue-good-table
486505
:columns="columns"
487506
:rows="rows"
488-
:groupOptions="{
507+
:group-options="{
489508
enabled: true,
490509
headerPosition: 'bottom'
491510
}">

README/images/vgt-table.checkbox.png

108 KB
Loading

dev/App.vue

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<template>
22
<div>
3-
<p>
4-
Scenario 1: If you click on "Auto filter name" and then
5-
Reset, it works. Then, uncoment the line 15, retry, it doesnt work.
6-
</p>
7-
<p>
8-
Scenario 2: Resetting by "=null" (uncomment line 16),
9-
autofilter Name + Reset => it works. However, Autofilter Age + Reset does not work
10-
</p><br>
113
<a href="#" @click.stop="autofilter('name')">Auto filter Name</a>&nbsp;&nbsp;
124
<a href="#" @click.stop="autofilter('age')">Auto filter age</a>
135
&nbsp;&nbsp;
@@ -16,12 +8,18 @@
168
<vue-good-table
179
:columns="columns"
1810
:rows="rows"
11+
mode=""
12+
@on-select-all="onSelectAll"
13+
@on-row-click="selectRow"
14+
:select-options="{
15+
enabled: true,
16+
}"
1917
:search-options="{
2018
enabled: false,
2119
}"
2220
:pagination-options="{
2321
enabled: true,
24-
perPage: 2,
22+
perPage: 3,
2523
setCurrentPage: 1,
2624
}">
2725
</vue-good-table>
@@ -90,6 +88,31 @@ export default {
9088
};
9189
},
9290
methods: {
91+
onSelectAll(params) {
92+
console.log(params);
93+
// this.unselectAll();
94+
// if (params.selected) {
95+
// for (let i = 0; i < params.selectedRows.length; i++) {
96+
// // lets get the original index of the row
97+
// const originalIndex = params.selectedRows[i].originalIndex;
98+
// // now lets set that row's selected value to be true
99+
// this.$set(this.rows[originalIndex], 'selected', true);
100+
// }
101+
// }
102+
},
103+
unselectAll() {
104+
for (let i = 0; i < this.rows.length; i++) {
105+
this.$set(this.rows[i], 'selected', false);
106+
}
107+
},
108+
selectRow(params) {
109+
console.log(params.row, params.pageIndex, params.selected);
110+
// if (this.rows[row.originalIndex].selected) {
111+
// this.$set(this.rows[row.originalIndex], 'selected', false);
112+
// } else {
113+
// this.$set(this.rows[row.originalIndex], 'selected', true);
114+
// }
115+
},
93116
autofilter(type) {
94117
if (type == 'name') {
95118
this.columns[0].filterOptions.filterValue = 'John';

dev/grouped-table.vue

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<vue-good-table
44
:columns="columns"
55
:rows="rows"
6+
:line-numbers="true"
7+
:select-options="{enabled: true}"
8+
@on-select-all="onSelectAll"
69
:group-options="{
710
enabled: true,
811
headerPosition: 'bottom',
@@ -77,6 +80,9 @@ export default {
7780
computed: {
7881
},
7982
methods: {
83+
onSelectAll(params) {
84+
console.log(params);
85+
},
8086
sumCount(rowObj) {
8187
let sum = 0;
8288
for (let i = 0; i < rowObj.children.length; i++) {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
"lodash.clone": "^4.5.0",
4444
"lodash.clonedeep": "^4.5.0",
4545
"lodash.filter": "^4.6.0",
46-
"lodash.foreach": "^4.5.0",
47-
"poi": "^9.6.13"
46+
"lodash.foreach": "^4.5.0"
4847
},
4948
"devDependencies": {
49+
"poi": "^9.6.13",
5050
"bili": "^2.2.7",
5151
"rollup-plugin-vue": "^3.0.0",
5252
"sass-loader": "^6.0.6",

0 commit comments

Comments
 (0)