<template>
<account-layout :active="3">
<div class="col-lg-12 control-section">
<div>
<ejs-grid ref="grid" id="grid" :dataSource="users" :detailTemplate="'detailTemplate'"
class="sortingenabled" :allowPaging='true' :allowSorting='true' :sortSettings='initialSort'
:pageSettings='pageSettings' :editSettings='editSettings' :toolbar='toolbar'
:recordClick="recordClick" :commandClick='commandClick'>
<e-columns>
<e-column field='username' headerText='Username' width='125' textAlign='Center'
:allowEditing='false'></e-column>
<e-column field='createdAt' headerText='Registration Date' width='135' textAlign='Center'
format='yMd' :allowEditing='false'></e-column>
<e-column field='verified' headerText='Verified' width='100' editType='booleanedit'
:edit='boolParams' displayAsCheckBox='true' type='boolean' textAlign='Center'></e-column>
<e-column headerText='Manage Records' width='160' :commands='commands'></e-column>
</e-columns>
<template v-slot:detailTemplate="users">
<table class="detailtable" width="100%">
<colgroup>
<col width="35%">
<col width="35%">
<col width="30%">
</colgroup>
<tbody>
<tr>
<td>
<span style="font-weight: 500;">Email: </span> {{ users.data.email }}
</td>
<td>
<span style="font-weight: 500;">Phone Number: </span>
{{ users.data.phone_number }}
</td>
</tr>
</tbody>
</table>
</template>
</ejs-grid>
</div>
</div>
</account-layout>
</template>
<script>
import { mapActions, mapState } from 'pinia';
import { useUserStore } from '../../../store/UserStore';
import DataLayout from "../../../components/Layouts/DataLayout.vue";
import { DetailRow, Edit, Sort, Page, Toolbar, CommandColumn } from "@syncfusion/ej2-vue-grids";
export default {
components: {
DataLayout,
},
provide: {
grid: [DetailRow, Edit, Sort, Page, Toolbar, CommandColumn]
},
async created() {
this.getUsers();
this.updateUser();
},
data: () => {
return {
initialSort: {
columns: [
{ field: 'username', direction: 'Ascending' },
]
},
pageSettings: { pageCount: 3 },
toolbar: ["Search"],
editSettings: { allowEditing: true, showDeleteConfirmDialog: true },
commands: [
{ type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat', } },
{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } },
{ type: 'Save', buttonOption: { cssClass: 'e-flat', iconCss: 'e-update e-icons' } },
{ type: 'Cancel', buttonOption: { cssClass: 'e-flat', iconCss: 'e-cancel-icon e-icons' } }
],
};
},
methods: {
...mapActions(useUserStore, ['getUsers']),
...mapActions(useUserStore, ['updateUser']),
recordClick: async function (args) {
console.log(this.$refs.grid.ej2Instances)
console.log(args)
},
commandClick: async function (args) {
if (args.commandColumn.type === 'Edit') {
}
if (args.commandColumn.type === 'Save') {
try {
await this.updateUser({
id: args.rowData.id,
verified: args.rowData.verified, // HERE NEED TO GET THE UPDATED CHECKBOX VALUE
});
} catch (error) {
console.log("Error! Could not update the user verification status!", error);
}
}
},
},
computed: {
...mapState(useUserStore, ['users']),
},
}
</script >
<style>
@import "../../../../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-calendars/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../../../../node_modules/@syncfusion/ej2-vue-grids/styles/material.css";
</style>