diff --git a/src/views/datatable/DataTableContextMenuDemo.vue b/src/views/datatable/DataTableContextMenuDemo.vue
index c5d347697..5f4b70311 100755
--- a/src/views/datatable/DataTableContextMenuDemo.vue
+++ b/src/views/datatable/DataTableContextMenuDemo.vue
@@ -9,11 +9,15 @@
-
-
-
-
-
+
+
+
+
+
+
+ {{formatCurrency(slotProps.data.price)}}
+
+
@@ -25,11 +29,15 @@
-<DataTable :value="cars" contextMenu :contextMenuSelection.sync="selectedCar" @row-contextmenu="onRowContextMenu">
- <Column field="vin" header="Vin"></Column>
- <Column field="year" header="Year"></Column>
- <Column field="brand" header="Brand"></Column>
- <Column field="color" header="Color"></Column>
+<DataTable :value="products" contextMenu :contextMenuSelection.sync="selectedProduct" @row-contextmenu="onRowContextMenu">
+ <Column field="code" header="Code"></Column>
+ <Column field="name" header="Name"></Column>
+ <Column field="category" header="Category"></Column>
+ <Column field="price" header="Price">
+ <template #body="slotProps">
+ {{formatCurrency(slotProps.data.price)}}
+ </template>
+ </Column>
</DataTable>
<ContextMenu :model="menuModel" ref="cm" />
@@ -37,37 +45,40 @@
-import CarService from '../../service/CarService';
+import ProductService from '../../service/ProductService';
export default {
data() {
return {
- cars: null,
- selectedCar: null,
+ products: null,
+ selectedProduct: null,
menuModel: [
- {label: 'View', icon: 'pi pi-fw pi-search', command: () => this.viewCar(this.selectedCar)},
- {label: 'Delete', icon: 'pi pi-fw pi-times', command: () => this.deleteCar(this.selectedCar)}
+ {label: 'View', icon: 'pi pi-fw pi-search', command: () => this.viewProduct(this.selectedProduct)},
+ {label: 'Delete', icon: 'pi pi-fw pi-times', command: () => this.deleteProduct(this.selectedProduct)}
]
}
},
- carService: null,
+ productService: null,
created() {
- this.carService = new CarService();
+ this.productService = new ProductService();
},
mounted() {
- this.carService.getCarsSmall().then(data => this.cars = data);
+ this.productService.getProductsSmall().then(data => this.products = data);
},
methods: {
onRowContextMenu(event) {
this.$refs.cm.show(event.originalEvent);
},
- viewCar(car) {
- this.$toast.add({severity: 'info', summary: 'Car Selected', detail: car.vin + ' - ' + car.brand});
+ viewProduct(product) {
+ this.$toast.add({severity: 'info', summary: 'Product Selected', detail: product.name});
},
- deleteCar(car) {
- this.cars = this.cars.filter((c) => c.vin !== car.vin);
- this.$toast.add({severity: 'info', summary: 'Car Deleted', detail: car.vin + ' - ' + car.brand});
- this.selectedCar = null;
+ deleteProduct(product) {
+ this.products = this.products.filter((p) => p.id !== product.id);
+ this.$toast.add({severity: 'info', summary: 'Product Deleted', detail: product.name});
+ this.selectedProduct = null;
+ },
+ formatCurrency(value) {
+ return value.toLocaleString('en-US', {style: 'currency', currency: 'USD'});
}
}
}
@@ -79,37 +90,40 @@ export default {
@@ -171,8 +175,7 @@ export default {
.p-datatable-tbody > tr > td {
text-align: left;
display: block;
- border: 0 none !important;
- width: 100% !important;
+ width: 100%;
float: left;
clear: left;
border: 0 none;
@@ -184,6 +187,10 @@ export default {
margin: -.4em 1em -.4em -.4rem;
font-weight: bold;
}
+
+ &:last-child {
+ border-bottom: 1px solid var(--surface-d);
+ }
}
}
}