5
5
<slot name =" toolbar" ></slot >
6
6
</div >
7
7
<div class =" filter" v-if =" hasData" >
8
- <SearchBox v-model =" filterValue" :compact =" true" />
8
+ <SearchBox v-model =" filterValue" :placeholder = " searchPlaceholder " : compact =" true" />
9
9
</div >
10
10
</div >
11
11
<table v-if =" hasData" >
12
12
<thead >
13
13
<tr >
14
- <th v-for =" (col, id) in columns" v-show =" !col.hide" :key =" col.name" :class =" thClasses(id)" @click =" enableSort(id)" :title =" thTitle(id)" >{{ col.name }}</th >
14
+ <th v-for =" (col, id) in columns" v-show =" !col.hide" :key =" col.name" :width = " col.width " : class =" thClasses(id)" @click =" enableSort(id)" :title =" thTitle(id)" >{{ col.name }}</th >
15
15
</tr >
16
16
</thead >
17
17
<tbody >
18
18
<tr v-for =" (row, i) in view" :key =" i" >
19
- <td v-for =" (col, id) in columns" v-show =" !col.hide" :key =" `${col.name}_${i }`"
19
+ <td v-for =" (col, id) in columns" v-show =" !col.hide" :key =" `${col.name}_${id }`"
20
20
:class =" [id, {'edit': canEdit(col)}]"
21
21
:title =" canEdit(col) ? 'Double-click to change the value' : false"
22
22
@dblclick =" onDblClick($event, row, col, id)"
37
37
</tbody >
38
38
</table >
39
39
<div class =" no-data" v-else >{{ noDataMessage }}</div >
40
+ <AsyncButton v-if =" hasMore" :fa =" fa" icon =" fas fa-sync" class =" has-more-button" :fn =" next" >Load more...</AsyncButton >
40
41
</div >
41
42
</template >
42
43
@@ -47,6 +48,7 @@ import { DataTypes, Formatters } from '@radiantearth/stac-fields';
47
48
export default {
48
49
name: ' DataTable' ,
49
50
components: {
51
+ AsyncButton : () => import (' ./internal/AsyncButton.vue' ),
50
52
SearchBox : () => import (' ./SearchBox.vue' )
51
53
},
52
54
props: {
@@ -57,6 +59,15 @@ export default {
57
59
data: {
58
60
type: Array ,
59
61
default : () => ([])
62
+ },
63
+ next: {
64
+ type: Function ,
65
+ default: null
66
+ },
67
+ fa: {
68
+ // Whether to use Font Awesome icons or not
69
+ type: Boolean ,
70
+ default: false
60
71
}
61
72
},
62
73
data () {
@@ -85,6 +96,9 @@ export default {
85
96
columns: {
86
97
immediate: true ,
87
98
handler () {
99
+ if (this .hasMore ) {
100
+ return ;
101
+ }
88
102
for (let id in this .columns ) {
89
103
let direction = this .columns [id].sort ;
90
104
if ([' asc' , ' desc' ].includes (direction)) {
@@ -96,6 +110,9 @@ export default {
96
110
}
97
111
},
98
112
computed: {
113
+ hasMore () {
114
+ return typeof this .next === ' function' ;
115
+ },
99
116
columnCount () {
100
117
return Object .keys (this .columns ).length ;
101
118
},
@@ -104,6 +121,9 @@ export default {
104
121
},
105
122
hasFilter () {
106
123
return (typeof this .filterValue === ' string' && this .filterValue .length > 0 ) ? true : false ;
124
+ },
125
+ searchPlaceholder () {
126
+ return this .hasMore ? ` Search through subset of loaded data...` : ` Search...` ;
107
127
}
108
128
},
109
129
beforeCreate () {
@@ -196,7 +216,7 @@ export default {
196
216
thClasses (id ) {
197
217
let col = this .columns [id];
198
218
let classes = [id];
199
- if (col .sort !== false ) {
219
+ if (! this . hasMore && col .sort !== false ) {
200
220
classes .push (' sortable' );
201
221
if (this .sortState .id === id) {
202
222
classes .push (' sort-' + this .sortState .direction );
@@ -206,7 +226,7 @@ export default {
206
226
},
207
227
thTitle (id ) {
208
228
let col = this .columns [id];
209
- if (col .sort !== false ) {
229
+ if (! this . hasMore && col .sort !== false ) {
210
230
if (this .sortState .id === id && this .sortState .direction === ' asc' ) {
211
231
return " Click to sort column in descending order" ;
212
232
}
@@ -217,7 +237,7 @@ export default {
217
237
return null ;
218
238
},
219
239
enableSort (id , direction = null ) {
220
- if (this .columns [id].sort === false ) {
240
+ if (this .hasMore || this . columns [id].sort === false ) {
221
241
return ;
222
242
}
223
243
if (direction === null ) {
@@ -358,7 +378,7 @@ export default {
358
378
text-align : right ;
359
379
padding-left : 1em ;
360
380
min-width : 4em ;
361
- max-width : 20 em ;
381
+ max-width : 30 em ;
362
382
.edit {
363
383
cursor : pointer ;
364
384
}
0 commit comments