Newer
Older
<template>
<div class="flex items-center justify-center panel-table w-full md:w-auto pt-10">
<table
:id="id"
class="table table-striped table-bordered table-hover"
/>
</div>
</template>
<script>
const _ = require('lodash');
const $ = window.jQuery = require('jquery');
require('@/components/js/datatable');
let table;
export default {
mounted() {
const vm = this;
vm.createTable(vm.id, vm.data);
},
editUser(id) {
// eslint-disable-next-line
this.$router.push('/updateuser/' + id)
},
createTable(id, data) {
const vm = this;
_.forEach(data, (d) => {
d.DT_RowID = `${d.id}`;
});
const columns = [
{
title: 'ID',
data: 'id',
fnCreatedCell: (nTd, sData, oData) => {
$(nTd).html(`<a href="" class="edit-link"> ${sData}</a>`);
},
},
{
title: 'User ID',
{
title: 'Name',
data: 'full_name',
},
{
title: 'Email',
data: 'email',
},
{
title: 'Affiliation',
data: 'current_affiliation',
},
{
title: 'Profile Link',
data: 'profile_link',
},
{
title: 'Current Role',
data: 'current_role',
},
{
title: 'Motivation',
data: 'motivation_text',
},
{
title: 'Joined',
data: 'createdAt',
},
{
title: 'Updated',
data: 'updatedAt',
},
{
title: 'Status',
data: 'confirmed',
},
];
const nTableOptions = {
columns,
// aaSorting: [[ 0, 'asc' ]],
paging: true,
searching: true,
info: false,
data,
order: [], // order: [[0, 'asc']],
bDestroy: true, // Add this property to new setting,
oLanguage: {
},
dom: '<"row"<"col-sm-2"l><"col-sm-2"f><"col-sm-8"p>><"row"t><"row"<"col-sm-4"i><"col-sm-8"p>>'
};
const tableId = `#${id}`;
if (table) {
table.destroy();
$(tableId).empty();
}
table = $(tableId).DataTable(nTableOptions);
const tableBody = `${tableId} tbody`;
$(tableBody).on('click', 'tr td a.edit-link', (e) => {
e.preventDefault()
const tr = $(e.target).parent().parent();
const row = table.row(tr);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
});
},
},
}
</script>
<style scoped>
@import url('~@/assets/datatable.css');
select.form-control {
font-size: 12px;
padding: 3px 12px;
}
ul.pagination {
font-size: 1rem;
}
.form-inline .form-control {
height: 25px;
line-height: 25px;
vertical-align: middle;
}
.edit-link {
font-weight: bold;
color: #0065b9;
}
.pagination {
font-size: 1.2rem;
}
.panel-table {
font-size: 1.4rem;
margin-bottom: 20px;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, .05);
border-radius: 4px;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}
</style>