171 lines
5.3 KiB
Vue
Executable File
171 lines
5.3 KiB
Vue
Executable File
<template>
|
|
<div>
|
|
<div class="content-section introduction">
|
|
<div class="feature-intro">
|
|
<h1>DataTable <span>Templating</span></h1>
|
|
<p>Custom content at header, body and footer sections are supported via templating.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content-section implementation">
|
|
<div class="card">
|
|
<DataTable :value="products">
|
|
<template #header>
|
|
<div class="table-header">
|
|
Products
|
|
<Button icon="pi pi-refresh" />
|
|
</div>
|
|
</template>
|
|
<Column field="name" header="Name"></Column>
|
|
<Column header="Image">
|
|
<template #body="slotProps">
|
|
<img :src="'demo/images/product/' + slotProps.data.image" :alt="slotProps.data.image" class="product-image" />
|
|
</template>
|
|
</Column>
|
|
<Column field="price" header="Price">
|
|
<template #body="slotProps">
|
|
{{formatCurrency(slotProps.data.price)}}
|
|
</template>
|
|
</Column>
|
|
<Column field="category" header="Category"></Column>
|
|
<Column field="rating" header="Reviews">
|
|
<template #body="slotProps">
|
|
<Rating :modelValue="slotProps.data.rating" :readonly="true" :cancel="false" />
|
|
</template>
|
|
</Column>
|
|
<Column header="Status">
|
|
<template #body="slotProps">
|
|
<span :class="'product-badge status-' + slotProps.data.inventoryStatus.toLowerCase()">{{slotProps.data.inventoryStatus}}</span>
|
|
</template>
|
|
</Column>
|
|
<template #footer>
|
|
In total there are {{products ? products.length : 0 }} products.
|
|
</template>
|
|
</DataTable>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content-section documentation">
|
|
<TabView>
|
|
<TabPanel header="Source">
|
|
<pre v-code>
|
|
<code><template v-pre>
|
|
<DataTable :value="products">
|
|
<template #header>
|
|
<div class="table-header">
|
|
Products
|
|
<Button icon="pi pi-refresh" />
|
|
</div>
|
|
</template>
|
|
<Column field="name" header="Name"></Column>
|
|
<Column header="Image">
|
|
<template #body="slotProps">
|
|
<img :src="'demo/images/product/' + slotProps.data.image" :alt="slotProps.data.image" class="product-image" />
|
|
</template>
|
|
</Column>
|
|
<Column field="price" header="Price">
|
|
<template #body="slotProps">
|
|
{{formatCurrency(slotProps.data.price)}}
|
|
</template>
|
|
</Column>
|
|
<Column field="category" header="Category"></Column>
|
|
<Column field="rating" header="Reviews">
|
|
<template #body="slotProps">
|
|
<Rating :modelValue="slotProps.data.rating" :readonly="true" :cancel="false" />
|
|
</template>
|
|
</Column>
|
|
<Column header="Status">
|
|
<template #body="slotProps">
|
|
<span :class="'product-badge status-' + slotProps.data.inventoryStatus.toLowerCase()">{{slotProps.data.inventoryStatus}}</span>
|
|
</template>
|
|
</Column>
|
|
<template #footer>
|
|
In total there are {{products ? products.length : 0 }} products.
|
|
</template>
|
|
</DataTable>
|
|
</template>
|
|
</code></pre>
|
|
|
|
<pre v-code.script>
|
|
<code>
|
|
import ProductService from '../../service/ProductService';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
products: null
|
|
}
|
|
},
|
|
productService: null,
|
|
created() {
|
|
this.productService = new ProductService();
|
|
},
|
|
mounted() {
|
|
this.productService.getProductsSmall().then(data => this.products = data);
|
|
},
|
|
methods: {
|
|
formatCurrency(value) {
|
|
return value.toLocaleString('en-US', {style: 'currency', currency: 'USD'});
|
|
}
|
|
}
|
|
}
|
|
|
|
</code></pre>
|
|
|
|
<pre v-code.css>
|
|
<code>
|
|
.table-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.product-image {
|
|
width: 100px;
|
|
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23)
|
|
}
|
|
|
|
</code></pre>
|
|
|
|
</TabPanel>
|
|
</TabView>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import ProductService from '../../service/ProductService';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
products: null
|
|
}
|
|
},
|
|
productService: null,
|
|
created() {
|
|
this.productService = new ProductService();
|
|
},
|
|
mounted() {
|
|
this.productService.getProductsSmall().then(data => this.products = data);
|
|
},
|
|
methods: {
|
|
formatCurrency(value) {
|
|
return value.toLocaleString('en-US', {style: 'currency', currency: 'USD'});
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.table-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.product-image {
|
|
width: 100px;
|
|
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23)
|
|
}
|
|
</style> |