Skip to content

Commit 9e37038

Browse files
committed
Support defining the width of columns
1 parent 1821349 commit 9e37038

File tree

4 files changed

+53
-42
lines changed

4 files changed

+53
-42
lines changed

demo/app.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export default {
2020
columns: [
2121
{ label: 'Id', data: 'id' },
2222
{ label: 'Name', data: 'name' },
23-
{ label: 'Height', data: 'height', right: true, sortable: false },
24-
{ label: 'Weight', data: 'weight', right: true, sortable: false },
25-
{ label: 'Spawn chance', data: 'spawn_chance', right: true },
23+
{ label: 'Height', data: 'height', right: true, sortable: false, width: '80px' },
24+
{ label: 'Weight', data: 'weight', right: true, sortable: false, width: '80px' },
25+
{ label: 'Spawn chance', data: 'spawn_chance', right: true, width: '80px' },
2626
],
2727
data: ref<any>([]),
2828

src/column.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface Column {
33
data: string;
44
right?: boolean;
55
sortable?: boolean;
6+
width?: string;
67
};

src/datagrid.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
.dg {
1+
.dg-wrapper {
22
border: 1px solid #bdc3c7;
3+
position: relative;
4+
overflow: hidden
5+
}
6+
7+
.dg-scroller {
8+
overflow: auto;
9+
height: 100%
10+
}
11+
12+
.dg {
313
border-spacing: 0;
4-
display: block;
514
table-layout: fixed;
6-
empty-cells: show;
7-
overflow: auto;
8-
height: 100%;
15+
empty-cells: show;
916
}
1017

1118
.dg-header, .dg-cell {

src/datagrid.vue

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
11
<template>
2-
<div style='position: relative; overflow: hidden'>
3-
<table class='dg' :class='selected && "dg-selectable"'
4-
v-virtual='virtual'>
5-
<thead>
6-
<tr>
7-
<th v-if='selected' class='dg-header'>
8-
<!-- FIXME: v-model='allSelected' when alpha.6 is published -->
9-
<input type='checkbox' :checked='allSelected' @change='allSelected = $event.target.checked' :indeterminate='allSelected === 1' />
10-
</th>
11-
<th v-for='(c, i) of columns'
12-
:key='i'
13-
class='dg-header' :class='{ "dg-right": c.right, "dg-sort": c.sortable !== false }'
14-
@click='sortOn(c, $event.ctrlKey)'>
15-
{{ c.label }}
16-
<sort-indicator :sort='sort' :column='c' />
17-
</th>
18-
<th class='dg-header dg-fill' />
19-
</tr>
20-
<tr v-if='loading' class='dg-loader'></tr>
21-
</thead>
22-
<tbody @click='toggle($event.target)'>
23-
<tr :style='{ height: virtual.topGap + "px" }'></tr>
24-
<tr v-for='d of virtual' :key='d.id'
25-
class='dg-row' :class='selected && selected.has(d) && "dg-selected"'
26-
:true-value='d'>
27-
<td v-if='selected' class='dg-cell'>
28-
<input type='checkbox' :checked='selected.has(d)' />
29-
</td>
30-
<td v-for='c of columns' v-text='d[c.data]' class='dg-cell' :class='c.right && "dg-right"' />
31-
<td class='dg-cell dg-fill' />
32-
</tr>
33-
<tr :style='{ height: virtual.bottomGap + "px" }'></tr>
34-
</tbody>
35-
</table>
2+
<div class='dg-wrapper'>
3+
<div class='dg-scroller'>
4+
<table class='dg' :class='selected && "dg-selectable"'
5+
v-virtual='virtual'>
6+
<thead>
7+
<tr>
8+
<th v-if='selected' class='dg-header'>
9+
<!-- FIXME: v-model='allSelected' when alpha.6 is published -->
10+
<input type='checkbox' :checked='allSelected' @change='allSelected = $event.target.checked' :indeterminate='allSelected === 1' />
11+
</th>
12+
<th v-for='(c, i) of columns'
13+
:key='i'
14+
class='dg-header' :class='{ "dg-right": c.right, "dg-sort": c.sortable !== false }'
15+
:style='{ width: c.width }'
16+
@click='sortOn(c, $event.ctrlKey)'>
17+
{{ c.label }}
18+
<sort-indicator :sort='sort' :column='c' />
19+
</th>
20+
<th class='dg-header dg-fill' />
21+
</tr>
22+
<tr v-if='loading' class='dg-loader'></tr>
23+
</thead>
24+
<tbody @click='toggle($event.target)'>
25+
<tr :style='{ height: virtual.topGap + "px" }'></tr>
26+
<tr v-for='d of virtual' :key='d.id'
27+
class='dg-row' :class='selected && selected.has(d) && "dg-selected"'
28+
:true-value='d'>
29+
<td v-if='selected' class='dg-cell'>
30+
<input type='checkbox' :checked='selected.has(d)' />
31+
</td>
32+
<td v-for='c of columns' v-text='d[c.data]' class='dg-cell' :class='c.right && "dg-right"' />
33+
<td class='dg-cell dg-fill' />
34+
</tr>
35+
<tr :style='{ height: virtual.bottomGap + "px" }'></tr>
36+
</tbody>
37+
</table>
38+
</div>
3639
</div>
3740
</template>
3841

0 commit comments

Comments
 (0)