106 lines
3.1 KiB
Vue
Executable File
106 lines
3.1 KiB
Vue
Executable File
<template>
|
|
<div>
|
|
<div class="content-section introduction">
|
|
<div class="feature-intro">
|
|
<h1>DataTable <span>Reorder</span></h1>
|
|
<p>Order of the columns and rows can be changed using drag and drop.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content-section implementation">
|
|
<div class="card">
|
|
<DataTable :value="cars" :reorderableColumns="true" @column-reorder="onColReorder" @row-reorder="onRowReorder">
|
|
<Column :rowReorder="true" headerStyle="width: 3em" :reorderableColumn="false" />
|
|
<Column v-for="col of columns" :field="col.field" :header="col.header" :key="col.field"></Column>
|
|
</DataTable>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content-section documentation">
|
|
<TabView>
|
|
<TabPanel header="Source">
|
|
<CodeHighlight>
|
|
<template v-pre>
|
|
<DataTable :value="cars" :reorderableColumns="true" @column-reorder="onColReorder" @row-reorder="onRowReorder">
|
|
<Column :rowReorder="true" headerStyle="width: 3em" :reorderableColumn="false" />
|
|
<Column v-for="col of columns" :field="col.field" :header="col.header" :key="col.field"></Column>
|
|
</DataTable>
|
|
</template>
|
|
</CodeHighlight>
|
|
|
|
<CodeHighlight lang="javascript">
|
|
import CarService from '../../service/CarService';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
columns: null,
|
|
cars: null
|
|
}
|
|
},
|
|
carService: null,
|
|
created() {
|
|
this.carService = new CarService();
|
|
|
|
this.columns = [
|
|
{field: 'vin', header: 'Vin'},
|
|
{field: 'year', header: 'Year'},
|
|
{field: 'brand', header: 'Brand'},
|
|
{field: 'color', header: 'Color'}
|
|
];
|
|
},
|
|
mounted() {
|
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
|
},
|
|
methods: {
|
|
onColReorder(event) {
|
|
this.$toast.add({severity:'success', summary: 'Column Reordered', life: 3000});
|
|
},
|
|
onRowReorder(event) {
|
|
this.cars = event.value;
|
|
this.$toast.add({severity:'success', summary: 'Rows Reordered', life: 3000});
|
|
}
|
|
}
|
|
}
|
|
</CodeHighlight>
|
|
</TabPanel>
|
|
</TabView>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import CarService from '../../service/CarService';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
columns: null,
|
|
cars: null
|
|
}
|
|
},
|
|
carService: null,
|
|
created() {
|
|
this.carService = new CarService();
|
|
|
|
this.columns = [
|
|
{field: 'vin', header: 'Vin'},
|
|
{field: 'year', header: 'Year'},
|
|
{field: 'brand', header: 'Brand'},
|
|
{field: 'color', header: 'Color'}
|
|
];
|
|
},
|
|
mounted() {
|
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
|
},
|
|
methods: {
|
|
onColReorder() {
|
|
this.$toast.add({severity:'success', summary: 'Column Reordered', life: 3000});
|
|
},
|
|
onRowReorder(event) {
|
|
this.cars = event.value;
|
|
this.$toast.add({severity:'success', summary: 'Rows Reordered', life: 3000});
|
|
}
|
|
}
|
|
}
|
|
</script> |