196 lines
6.7 KiB
Vue
196 lines
6.7 KiB
Vue
<template>
|
|
<div>
|
|
<DataTableSubMenu />
|
|
|
|
<div class="content-section introduction">
|
|
<div class="feature-intro">
|
|
<h1>DataTable - Row Expansion</h1>
|
|
<p>A row can be expanded to display additional content.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content-section implementation">
|
|
<DataTable :value="cars" :expandedRows.sync="expandedRows" dataKey="vin"
|
|
@row-expand="onRowExpand" @row-collapse="onRowCollapse">
|
|
<template #header>
|
|
<div class="table-header-container">
|
|
<Button icon="pi pi-plus" label="Expand All" @click="expandAll" />
|
|
<Button icon="pi pi-minus" label="Collapse All" @click="collapseAll" />
|
|
</div>
|
|
</template>
|
|
<Column :expander="true" headerStyle="width: 3em" />
|
|
<Column field="vin" header="Vin"></Column>
|
|
<Column field="year" header="Year"></Column>
|
|
<Column field="brand" header="Brand"></Column>
|
|
<Column field="color" header="Color"></Column>
|
|
<template #expansion="slotProps">
|
|
<div class="car-details">
|
|
<div>
|
|
<img :src="'demo/images/car/' + slotProps.data.brand + '.png'" :alt="slotProps.data.brand"/>
|
|
<div class="p-grid">
|
|
<div class="p-col-12">Vin: <b>{{slotProps.data.vin}}</b></div>
|
|
<div class="p-col-12">Year: <b>{{slotProps.data.year}}</b></div>
|
|
<div class="p-col-12">Brand: <b>{{slotProps.data.brand}}</b></div>
|
|
<div class="p-col-12">Color: <b>{{slotProps.data.color}}</b></div>
|
|
</div>
|
|
</div>
|
|
<Button icon="pi pi-search"></Button>
|
|
</div>
|
|
</template>
|
|
</DataTable>
|
|
</div>
|
|
|
|
<div class="content-section documentation">
|
|
<TabView>
|
|
<TabPanel header="Source">
|
|
<CodeHighlight>
|
|
<template v-pre>
|
|
<DataTable :value="cars" :expandedRows.sync="expandedRows" dataKey="vin"
|
|
@row-expand="onRowExpand" @row-collapse="onRowCollapse">
|
|
<template #header>
|
|
<div class="table-header-container">
|
|
<Button icon="pi pi-plus" label="Expand All" @click="expandAll" />
|
|
<Button icon="pi pi-minus" label="Collapse All" @click="collapseAll" />
|
|
</div>
|
|
</template>
|
|
<Column :expander="true" headerStyle="width: 3em" />
|
|
<Column field="vin" header="Vin"></Column>
|
|
<Column field="year" header="Year"></Column>
|
|
<Column field="brand" header="Brand"></Column>
|
|
<Column field="color" header="Color"></Column>
|
|
<template #expansion="slotProps">
|
|
<div class="car-details">
|
|
<div>
|
|
<img :src="'demo/images/car/' + slotProps.data.brand + '.png'" :alt="slotProps.data.brand"/>
|
|
<div class="p-grid">
|
|
<div class="p-col-12">Vin: <b>{{slotProps.data.vin}}</b></div>
|
|
<div class="p-col-12">Year: <b>{{slotProps.data.year}}</b></div>
|
|
<div class="p-col-12">Brand: <b>{{slotProps.data.brand}}</b></div>
|
|
<div class="p-col-12">Color: <b>{{slotProps.data.color}}</b></div>
|
|
</div>
|
|
</div>
|
|
<Button icon="pi pi-search"></Button>
|
|
</div>
|
|
</template>
|
|
</DataTable>
|
|
</template>
|
|
</CodeHighlight>
|
|
|
|
<CodeHighlight lang="javascript">
|
|
import CarService from '../../service/CarService';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
cars: null,
|
|
expandedRows: []
|
|
}
|
|
},
|
|
carService: null,
|
|
created() {
|
|
this.carService = new CarService();
|
|
},
|
|
mounted() {
|
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
|
},
|
|
methods: {
|
|
onRowExpand(event) {
|
|
this.$toast.add({severity: 'info', summary: 'Row Expanded', detail: 'Vin: ' + event.data.vin, life: 3000});
|
|
},
|
|
onRowCollapse(event) {
|
|
this.$toast.add({severity: 'success', summary: 'Row Collapsed', detail: 'Vin: ' + event.data.vin, life: 3000});
|
|
},
|
|
expandAll() {
|
|
this.expandedRows = this.cars.filter(car => car.vin);
|
|
this.$toast.add({severity: 'success', summary: 'All Rows Expanded', life: 3000});
|
|
},
|
|
collapseAll() {
|
|
this.expandedRows = null;
|
|
this.$toast.add({severity: 'success', summary: 'All Rows Collapsed', life: 3000});
|
|
}
|
|
}
|
|
}
|
|
</CodeHighlight>
|
|
</TabPanel>
|
|
</TabView>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import CarService from '../../service/CarService';
|
|
import DataTableSubMenu from './DataTableSubMenu';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
cars: null,
|
|
expandedRows: []
|
|
}
|
|
},
|
|
carService: null,
|
|
created() {
|
|
this.carService = new CarService();
|
|
},
|
|
mounted() {
|
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
|
},
|
|
methods: {
|
|
onRowExpand(event) {
|
|
this.$toast.add({severity: 'info', summary: 'Row Expanded', detail: 'Vin: ' + event.data.vin, life: 3000});
|
|
},
|
|
onRowCollapse(event) {
|
|
this.$toast.add({severity: 'success', summary: 'Row Collapsed', detail: 'Vin: ' + event.data.vin, life: 3000});
|
|
},
|
|
expandAll() {
|
|
this.expandedRows = this.cars.filter(car => car.vin);
|
|
this.$toast.add({severity: 'success', summary: 'All Rows Expanded', life: 3000});
|
|
},
|
|
collapseAll() {
|
|
this.expandedRows = null;
|
|
this.$toast.add({severity: 'success', summary: 'All Rows Collapsed', life: 3000});
|
|
}
|
|
},
|
|
components: {
|
|
'DataTableSubMenu': DataTableSubMenu
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.table-header-container {
|
|
text-align: left;
|
|
|
|
button {
|
|
min-width: 10em;
|
|
|
|
&:first-child {
|
|
margin-right: .5em;
|
|
}
|
|
}
|
|
}
|
|
|
|
.car-details {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 2em;
|
|
|
|
& > div {
|
|
display: flex;
|
|
align-items: center;
|
|
|
|
img {
|
|
margin-right: 14px;
|
|
}
|
|
}
|
|
}
|
|
|
|
@media (max-width: 1024px) {
|
|
.car-details {
|
|
img {
|
|
width: 75px;
|
|
}
|
|
}
|
|
}
|
|
</style> |