263 lines
5.5 KiB
Vue
263 lines
5.5 KiB
Vue
![]() |
<template>
|
||
|
<div class="p-datatable p-component">
|
||
|
<slot></slot>
|
||
|
<div class="p-datatable-wrapper">
|
||
|
<table>
|
||
|
<thead class="p-datatable-thead">
|
||
|
<tr>
|
||
|
<th v-for="col of columns" :key="col.columnKey||col.field">
|
||
|
<span class="p-column-title" v-if="col.header">{{col.header}}</span>
|
||
|
</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody class="p-datatable-tbody">
|
||
|
<tr class="p-datatable-row" v-for="(rowData, index) of value" :key="getRowKey(rowData, index)">
|
||
|
<td v-for="col of columns" :key="col.columnKey||col.field">
|
||
|
{{resolveFieldData(rowData, col.field)}}
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import ObjectUtils from '../utils/ObjectUtils';
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
value: {
|
||
|
type: Array,
|
||
|
default: null
|
||
|
},
|
||
|
dataKey: {
|
||
|
type: String,
|
||
|
default: null
|
||
|
}
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
columns: []
|
||
|
};
|
||
|
},
|
||
|
mounted() {
|
||
|
this.columns = this.$children;
|
||
|
},
|
||
|
methods: {
|
||
|
getRowKey(rowData, index) {
|
||
|
return this.dataKey ? ObjectUtils.resolveFieldData(rowData, this.dataKey): index;
|
||
|
},
|
||
|
resolveFieldData(rowData, field) {
|
||
|
return ObjectUtils.resolveFieldData(rowData, field);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style>
|
||
|
.p-datatable {
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
.p-datatable table {
|
||
|
border-collapse: collapse;
|
||
|
width: 100%;
|
||
|
table-layout: fixed;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-datatable-thead > tr > th,
|
||
|
.p-datatable .p-datatable-tbody > tr > td,
|
||
|
.p-datatable .p-datatable-tfoot > tr > td {
|
||
|
padding: .25em .5em;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-sortable-column {
|
||
|
cursor: pointer;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-sortable-column-icon {
|
||
|
vertical-align: middle;
|
||
|
}
|
||
|
|
||
|
.p-datatable-auto-layout > .p-datatable-wrapper {
|
||
|
overflow-x: auto;
|
||
|
}
|
||
|
|
||
|
.p-datatable-auto-layout > .p-datatable-wrapper > table {
|
||
|
table-layout: auto;
|
||
|
}
|
||
|
|
||
|
/* Sections */
|
||
|
.p-datatable-header,
|
||
|
.p-datatable-footer {
|
||
|
padding: .25em .5em;
|
||
|
text-align: center;
|
||
|
font-weight: bold;
|
||
|
}
|
||
|
|
||
|
.p-datatable-header {
|
||
|
border-bottom: 0 none;
|
||
|
}
|
||
|
|
||
|
.p-datatable-footer {
|
||
|
border-top: 0 none;
|
||
|
}
|
||
|
|
||
|
/* Paginator */
|
||
|
.p-datatable .p-paginator-top {
|
||
|
border-bottom: 0 none;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-paginator-bottom {
|
||
|
border-top: 0 none;
|
||
|
}
|
||
|
|
||
|
/* Scrollable */
|
||
|
.p-datatable-scrollable-wrapper {
|
||
|
position: relative;
|
||
|
}
|
||
|
.p-datatable-scrollable-header,
|
||
|
.p-datatable-scrollable-footer {
|
||
|
overflow: hidden;
|
||
|
border: 0 none;
|
||
|
}
|
||
|
|
||
|
.p-datatable-scrollable-body {
|
||
|
overflow: auto;
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
.p-datatable-scrollable-body > table > .p-datatable-tbody > tr:first-child > td {
|
||
|
border-top: 0 none;
|
||
|
}
|
||
|
|
||
|
.p-datatable-virtual-table {
|
||
|
position: absolute;
|
||
|
}
|
||
|
|
||
|
/* Frozen Columns */
|
||
|
.p-datatable-frozen-view .p-datatable-scrollable-body {
|
||
|
overflow: hidden;
|
||
|
}
|
||
|
|
||
|
.p-datatable-frozen-view > .p-datatable-scrollable-body > table > .p-datatable-tbody > tr > td:last-child {
|
||
|
border-right: 0 none;
|
||
|
}
|
||
|
|
||
|
.p-datatable-unfrozen-view {
|
||
|
position: absolute;
|
||
|
top: 0px;
|
||
|
}
|
||
|
|
||
|
/* Filter */
|
||
|
.p-column-filter {
|
||
|
width: 100%;
|
||
|
}
|
||
|
|
||
|
/* Resizable */
|
||
|
.p-datatable-resizable > .p-datatable-wrapper {
|
||
|
overflow-x: auto;
|
||
|
}
|
||
|
|
||
|
.p-datatable-resizable .p-datatable-thead > tr > th,
|
||
|
.p-datatable-resizable .p-datatable-tfoot > tr > td,
|
||
|
.p-datatable-resizable .p-datatable-tbody > tr > td {
|
||
|
overflow: hidden;
|
||
|
}
|
||
|
|
||
|
.p-datatable-resizable .p-resizable-column {
|
||
|
background-clip: padding-box;
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
.p-datatable-resizable-fit .p-resizable-column:last-child .p-column-resizer {
|
||
|
display: none;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-column-resizer {
|
||
|
display: block;
|
||
|
position: absolute !important;
|
||
|
top: 0;
|
||
|
right: 0;
|
||
|
margin: 0;
|
||
|
width: .5em;
|
||
|
height: 100%;
|
||
|
padding: 0px;
|
||
|
cursor:col-resize;
|
||
|
border: 1px solid transparent;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-column-resizer-helper {
|
||
|
width: 1px;
|
||
|
position: absolute;
|
||
|
z-index: 10;
|
||
|
display: none;
|
||
|
}
|
||
|
|
||
|
/* Edit */
|
||
|
.p-datatable .p-datatable-tbody > tr > td.p-cell-editing .p-component {
|
||
|
width: 100%;
|
||
|
}
|
||
|
|
||
|
/* Reorder */
|
||
|
.p-datatable-reorder-indicator-up,
|
||
|
.p-datatable-reorder-indicator-down {
|
||
|
position: absolute;
|
||
|
display: none;
|
||
|
}
|
||
|
|
||
|
/* Responsive */
|
||
|
.p-datatable-responsive .p-datatable-tbody > tr > td .p-column-title {
|
||
|
display: none;
|
||
|
}
|
||
|
|
||
|
@media screen and (max-width: 40em) {
|
||
|
.p-datatable-responsive .p-datatable-thead > tr > th,
|
||
|
.p-datatable-responsive .p-datatable-tfoot > tr > td {
|
||
|
display: none !important;
|
||
|
}
|
||
|
|
||
|
.p-datatable-responsive .p-datatable-tbody > tr > td {
|
||
|
text-align: left;
|
||
|
display: block;
|
||
|
border: 0 none;
|
||
|
width: 100% !important;
|
||
|
float: left;
|
||
|
clear: left;
|
||
|
}
|
||
|
|
||
|
.p-datatable-responsive .p-datatable-tbody > tr > td .p-column-title {
|
||
|
padding: .4em;
|
||
|
min-width: 30%;
|
||
|
display: inline-block;
|
||
|
margin: -.4em 1em -.4em -.4em;
|
||
|
font-weight: bold;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* Loader */
|
||
|
.p-datatable-loading-overlay {
|
||
|
position: absolute;
|
||
|
width: 100%;
|
||
|
height: 100%;
|
||
|
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=10)";
|
||
|
opacity: 0.1;
|
||
|
z-index: 1;
|
||
|
}
|
||
|
|
||
|
.p-datatable-loading-content {
|
||
|
position: absolute;
|
||
|
left: 50%;
|
||
|
top: 50%;
|
||
|
z-index: 2;
|
||
|
margin-top: -1em;
|
||
|
margin-left: -1em;
|
||
|
}
|
||
|
|
||
|
.p-datatable .p-datatable-loading-icon {
|
||
|
font-size: 2em;
|
||
|
}
|
||
|
|
||
|
</style>
|