diff --git a/src/views/datatable/DataTableCrudDemo.vue b/src/views/datatable/DataTableCrudDemo.vue index b1f0029c8..afc95a4f1 100644 --- a/src/views/datatable/DataTableCrudDemo.vue +++ b/src/views/datatable/DataTableCrudDemo.vue @@ -10,13 +10,52 @@
-

Basic

- - - - - + + + + + + + + + +
+
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + +
@@ -28,7 +67,10 @@ import DataTableSubMenu from './DataTableSubMenu'; export default { data() { return { - cars: null + cars: null, + dialogVisible: false, + car: null, + selectedCar: null } }, carService: null, @@ -38,8 +80,72 @@ export default { mounted() { this.carService.getCarsSmall().then(data => this.cars = data); }, + methods: { + addNewCar() { + this.car = {vin: this.generateVin(), year: '', brand: '', color: ''}; + this.dialogVisible = true; + }, + deleteCar() { + let index = this.findIndexByVin(this.car.vin); + this.cars = this.cars.filter((val,i) => i !== index); + this.dialogVisible = false; + this.car = null; + this.selectedCar = null; + }, + saveCar() { + let index = this.findIndexByVin(this.car.vin); + let cars = [...this.cars]; + if (index === -1) + cars.push(this.car); + else + cars[index] = this.car; + + this.cars = cars; + this.dialogVisible = false; + this.car = null; + this.selectedCar = null; + }, + onRowSelect(event) { + this.car = {...event.data}; + this.dialogVisible = true; + }, + generateVin() { + let result = ''; + let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let charactersLength = characters.length; + for ( var i = 0; i < 8; i++ ) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; + }, + findIndexByVin(vin) { + let index = -1; + for (let i = 0; i < this.cars.length; i++) { + if (this.cars[i].vin === vin) { + index = i; + break; + } + } + + return index; + } + }, components: { 'DataTableSubMenu': DataTableSubMenu } } - \ No newline at end of file + + + \ No newline at end of file