vi-grid-builder 1.0.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +240 -11
- package/ViGridBuilderPlugin.js +35 -36
- package/package.json +5 -2
- package/playground/.vscode/extensions.json +3 -0
- package/playground/README.md +29 -0
- package/playground/index.html +13 -0
- package/playground/jsconfig.json +8 -0
- package/playground/package-lock.json +2524 -0
- package/playground/package.json +20 -0
- package/playground/public/favicon.ico +0 -0
- package/playground/src/App.vue +84 -0
- package/playground/src/assets/base.css +86 -0
- package/playground/src/assets/logo.svg +1 -0
- package/playground/src/assets/main.css +35 -0
- package/playground/src/components/ActionsField.vue +99 -0
- package/playground/src/components/ClickableRow.vue +68 -0
- package/playground/src/components/ClientSideData.vue +86 -0
- package/playground/src/components/ColumnVisibility.vue +85 -0
- package/playground/src/components/CustomField.vue +64 -0
- package/playground/src/components/CustomHeader.vue +85 -0
- package/playground/src/components/GlobalOptions.vue +68 -0
- package/playground/src/components/LoadingSlot.vue +11 -0
- package/playground/src/components/PaginationOptions.vue +130 -0
- package/playground/src/components/RowSelect.vue +72 -0
- package/playground/src/components/ServerSideData.vue +62 -0
- package/playground/src/components/SortableColumnServerSide.vue +73 -0
- package/playground/src/components/TableStyle.vue +112 -0
- package/playground/src/components/fields/SampleCustomField.vue +24 -0
- package/playground/src/components/icons/IconCommunity.vue +7 -0
- package/playground/src/components/icons/IconDocumentation.vue +7 -0
- package/playground/src/components/icons/IconEcosystem.vue +7 -0
- package/playground/src/components/icons/IconSupport.vue +7 -0
- package/playground/src/components/icons/IconTooling.vue +19 -0
- package/playground/src/main.js +51 -0
- package/playground/vite.config.js +17 -0
- package/src/ViGridBuilder.scss +157 -58
- package/src/ViGridBuilder.vue +367 -207
- package/src/ViGridField.scss +1 -2
- package/src/ViGridField.vue +13 -6
- package/src/ViGridHeadCell.vue +32 -0
- package/src/ViGridHeadColumnCell.vue +42 -0
- package/src/ViGridHeader.vue +67 -0
- package/src/composables/useColumns.js +21 -0
- package/src/composables/useGridActions.js +17 -3
- package/src/composables/useGridSettings.js +18 -0
- package/src/composables/usePagination.js +39 -0
- package/src/composables/useRowHelper.js +38 -0
- package/src/composables/useRowSelect.js +53 -0
- package/src/composables/useSettings.js +29 -0
- package/src/composables/useSort.js +103 -0
- package/src/fields/ViGridActions.scss +0 -1
- package/src/fields/ViGridActions.vue +37 -13
- package/src/fields/ViGridCheckbox.vue +31 -0
- package/src/fields/ViGridNumber.vue +18 -0
- package/src/fields/partials/ViGridKebabMenu.scss +60 -25
- package/src/fields/partials/ViGridKebabMenu.vue +75 -54
- package/src/fields/partials/{ViGridBuilderActions.vue → ViGridSimpleActions.vue} +3 -3
- package/src/settings/GridSettings.js +24 -0
- package/vite.config.js +12 -2
- package/src/examples/App.vue +0 -123
- package/src/examples/components/TableTitle.vue +0 -20
- package/src/examples/main.js +0 -11
- /package/src/fields/partials/{ViGridBuilderActions.scss → ViGridSimpleActions.scss} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<th class="vi-header-cell vi-cell" :colspan="colspan">
|
|
3
|
+
<div class="vi-header-cell-content" :class="align">
|
|
4
|
+
<slot>
|
|
5
|
+
</slot>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
</th>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
import {FontAwesomeIcon} from "@fortawesome/vue-fontawesome";
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
components: {FontAwesomeIcon},
|
|
16
|
+
props: {
|
|
17
|
+
align:{
|
|
18
|
+
type: String,
|
|
19
|
+
default: 'left'
|
|
20
|
+
},
|
|
21
|
+
colspan:{
|
|
22
|
+
type: Number,
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<style scoped lang="scss">
|
|
31
|
+
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<vi-grid-head-cell :class="sortableState" :align="column.align ?? align">
|
|
3
|
+
<template #default>
|
|
4
|
+
<div v-if="column.sortable" class="sort-button">
|
|
5
|
+
<font-awesome-icon v-if="sortableState === 'descending'"
|
|
6
|
+
:icon="['fas', 'chevron-down']"
|
|
7
|
+
@click="$emit('sort', column)"/>
|
|
8
|
+
<font-awesome-icon v-else :icon="['fas', 'chevron-up']" @click="$emit('sort', column)"/>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<slot>{{ column.label }}
|
|
12
|
+
</slot>
|
|
13
|
+
</template>
|
|
14
|
+
</vi-grid-head-cell>
|
|
15
|
+
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
import {FontAwesomeIcon} from "@fortawesome/vue-fontawesome";
|
|
20
|
+
import ViGridHeadCell from "./ViGridHeadCell.vue";
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
components: {ViGridHeadCell, FontAwesomeIcon},
|
|
24
|
+
props: {
|
|
25
|
+
column: {
|
|
26
|
+
type: Object,
|
|
27
|
+
required: true
|
|
28
|
+
},
|
|
29
|
+
align: {
|
|
30
|
+
type: String,
|
|
31
|
+
},
|
|
32
|
+
sortableState: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<style scoped lang="scss">
|
|
41
|
+
|
|
42
|
+
</style>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<thead>
|
|
5
|
+
<tr v-if="title" class="vi-header-row vi-table-row vi-title-row">
|
|
6
|
+
<th :colspan="visibleColumns.length" class="title">
|
|
7
|
+
<slot name="title" :title="title">
|
|
8
|
+
<component v-if="defaultSlots.title" :is="defaultSlots.title" :title="title"/>
|
|
9
|
+
<span v-else>{{title}}</span>
|
|
10
|
+
</slot>
|
|
11
|
+
</th>
|
|
12
|
+
</tr>
|
|
13
|
+
<tr class="vi-header-row vi-table-row">
|
|
14
|
+
<th v-if="selectable" class="vi-select-header vi-select-cell">
|
|
15
|
+
<vi-grid-checkbox
|
|
16
|
+
|
|
17
|
+
name="masterSelect"
|
|
18
|
+
:value="selectedRows?.length === rows?.length"
|
|
19
|
+
@checkboxClicked="toggleMasterSelect($event.value)"
|
|
20
|
+
/>
|
|
21
|
+
</th>
|
|
22
|
+
<th v-for="column in visibleColumns" :key="column.name" class="vi-header-cell vi-cell">
|
|
23
|
+
|
|
24
|
+
<span> <button @click="sortData(column)"> Sortt {{pagination.sortBy}}</button></span>
|
|
25
|
+
<slot :name="`vi-header-cell-${column.name}`" :column="column">{{column.label}}</slot>
|
|
26
|
+
</th>
|
|
27
|
+
|
|
28
|
+
</tr>
|
|
29
|
+
</thead>
|
|
30
|
+
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<style scoped lang="scss">
|
|
34
|
+
|
|
35
|
+
</style>
|
|
36
|
+
|
|
37
|
+
<script>
|
|
38
|
+
|
|
39
|
+
import useColumns from "./composables/useColumns.js";
|
|
40
|
+
import useRowHelper from "./composables/useRowHelper.js";
|
|
41
|
+
import useSort from "./composables/useSort.js";
|
|
42
|
+
import ViGridCheckbox from "@/fields/ViGridCheckbox.vue";
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
name: 'ViGridHeader',
|
|
46
|
+
components: {ViGridCheckbox},
|
|
47
|
+
props: {
|
|
48
|
+
title: String,
|
|
49
|
+
defaultSlots: Object,
|
|
50
|
+
selectable: Boolean,
|
|
51
|
+
noDataLabel: String,
|
|
52
|
+
columns: Array,
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
setup(props) {
|
|
57
|
+
const {visibleColumns, totalColumns} = useColumns(props);
|
|
58
|
+
const {currentVisibleRows, selectedRows, toggleMasterSelect,toggleRowSelect} = useRowHelper(props);
|
|
59
|
+
const {currentVisibleRows, sort} = useSort(props);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
visibleColumns,
|
|
63
|
+
totalColumns,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {computed} from "vue";
|
|
2
|
+
|
|
3
|
+
export default function useColumns(props) {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const visibleColumns = computed(()=> {
|
|
7
|
+
return props.columns.filter(column => {
|
|
8
|
+
return column.isVisible === undefined || column.isVisible;
|
|
9
|
+
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const totalColumns = computed(()=> {
|
|
14
|
+
return !props.selectable ? visibleColumns.value.length:1 + visibleColumns.value.length
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
visibleColumns,
|
|
19
|
+
totalColumns
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {computed } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function useGridActions(props) {
|
|
1
|
+
import {computed, ref} from 'vue';
|
|
2
|
+
export function useGridActions(props, emit) {
|
|
4
3
|
|
|
5
4
|
const visibleActions = computed(() => props.actions.filter((action ) => {
|
|
6
5
|
if (action.isVisible === undefined) {
|
|
@@ -11,8 +10,23 @@ export function useGridActions(props) {
|
|
|
11
10
|
|
|
12
11
|
}));
|
|
13
12
|
|
|
13
|
+
const onActionClicked = (action) => {
|
|
14
|
+
emit(`action-clicked`, {action, row:props.row})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const toggleRowMenu = (row) => {
|
|
18
|
+
if (props.rowMenuOpened === row[props.rowKey]) {
|
|
19
|
+
emit('update:rowMenuOpened', null)
|
|
20
|
+
} else {
|
|
21
|
+
emit('update:rowMenuOpened', row[props.rowKey])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
14
26
|
// Return the computed variable
|
|
15
27
|
return {
|
|
16
28
|
visibleActions,
|
|
29
|
+
onActionClicked,
|
|
30
|
+
toggleRowMenu,
|
|
17
31
|
};
|
|
18
32
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {computed} from "vue";
|
|
2
|
+
import {inject} from 'vue';
|
|
3
|
+
|
|
4
|
+
export default function useGridSettings(props) {
|
|
5
|
+
|
|
6
|
+
const settings = computed(() => {
|
|
7
|
+
|
|
8
|
+
const defaultSettings = inject('ViGridSettings', {});
|
|
9
|
+
|
|
10
|
+
return Object.keys(defaultSettings).reduce((allSettings, key) => {
|
|
11
|
+
allSettings[key] = props[key]!==undefined ? props[key]:defaultSettings[key];
|
|
12
|
+
return allSettings;
|
|
13
|
+
}, {});
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
return {settings}
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {computed} from "vue";
|
|
2
|
+
export default function usePagination(props,emit,fetchData) {
|
|
3
|
+
const localPagination = computed({
|
|
4
|
+
get() {
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
page: props.pagination?.page,
|
|
8
|
+
rowsPerPage: props.pagination?.rowsPerPage
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
},
|
|
12
|
+
set(newValue) {
|
|
13
|
+
emit("update:pagination", {
|
|
14
|
+
...props.pagination,
|
|
15
|
+
...newValue
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const onPaginationChange = ({currentPage, rowsPerPage}) => {
|
|
21
|
+
let newPagination = {
|
|
22
|
+
...localPagination.value,
|
|
23
|
+
...currentPage && {page:currentPage},
|
|
24
|
+
...(rowsPerPage!== undefined) && {rowsPerPage},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
localPagination.value = newPagination;
|
|
28
|
+
if (props.serverMode) {
|
|
29
|
+
fetchData({pagination: newPagination})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
localPagination,
|
|
35
|
+
onPaginationChange
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {computed} from "vue";
|
|
2
|
+
|
|
3
|
+
import useSort from "./useSort";
|
|
4
|
+
import {globalGridSettings} from "../composables/useSettings.js";
|
|
5
|
+
|
|
6
|
+
export default function useRowHelper(props, emit) {
|
|
7
|
+
|
|
8
|
+
const {sortedRows} = useSort(props);
|
|
9
|
+
|
|
10
|
+
const totalRows = computed(() => {
|
|
11
|
+
return props.serverMode ? props.pagination?.rowsNumber:props.rows.length;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const currentVisibleRows = computed(() => {
|
|
15
|
+
if (props.serverMode || props.disablePagination) {
|
|
16
|
+
return sortedRows.value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let rowsPerPage = props.pagination?.rowsPerPage ?? globalGridSettings.value.rowsPerPage
|
|
20
|
+
const startIndex = (props.pagination.page - 1) * rowsPerPage;
|
|
21
|
+
const endIndex = startIndex + rowsPerPage;
|
|
22
|
+
|
|
23
|
+
return sortedRows.value.slice(startIndex, endIndex)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const onRowClicked = (row) => {
|
|
27
|
+
if (props.clickableRow) {
|
|
28
|
+
emit('rowClicked', row)
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
totalRows,
|
|
35
|
+
currentVisibleRows,
|
|
36
|
+
onRowClicked,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
import useRowHelper from "../composables/useRowHelper.js";
|
|
3
|
+
import {computed, ref} from "vue";
|
|
4
|
+
|
|
5
|
+
export default function useRowSelect(props, emit) {
|
|
6
|
+
|
|
7
|
+
let selectedRows = ref([]);
|
|
8
|
+
const {currentVisibleRows} = useRowHelper(props, emit);
|
|
9
|
+
const toggleRowSelect = (row, selected) => {
|
|
10
|
+
if (selected) {
|
|
11
|
+
selectedRows.value.push(row[props.rowKey])
|
|
12
|
+
} else {
|
|
13
|
+
selectedRows.value = selectedRows.value.filter(idx => idx!==row[props.rowKey])
|
|
14
|
+
}
|
|
15
|
+
emit('selectedRowsUpdate', selectedRows.value)
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const toggleMasterSelect = (selected) => {
|
|
20
|
+
if (selected) {
|
|
21
|
+
selectedRows.value = [
|
|
22
|
+
...selectedRows.value,
|
|
23
|
+
...currentVisibleRows.value.filter(row => !selectedRows.value.includes(row[props.rowKey])).map(row => row[props.rowKey])
|
|
24
|
+
]
|
|
25
|
+
} else {
|
|
26
|
+
const currentVisibleRowKeys = currentVisibleRows.value.map(row => row[props.rowKey]);
|
|
27
|
+
selectedRows.value = selectedRows.value.filter(rowKey => {
|
|
28
|
+
return !currentVisibleRowKeys.includes(rowKey)
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
emit('selectedRowsUpdate', selectedRows.value)
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const isRowSelected = (row) => {
|
|
36
|
+
|
|
37
|
+
return selectedRows.value.includes(row[props.rowKey]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const areAllRowsSelected = computed(() => {
|
|
41
|
+
|
|
42
|
+
const selectedFromCurrentRows = currentVisibleRows.value.filter(row => selectedRows.value.includes(row[props.rowKey]));
|
|
43
|
+
return selectedFromCurrentRows.length > 0 && selectedFromCurrentRows.length===currentVisibleRows.value.length;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
selectedRows,
|
|
48
|
+
toggleRowSelect,
|
|
49
|
+
toggleMasterSelect,
|
|
50
|
+
isRowSelected,
|
|
51
|
+
areAllRowsSelected
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {computed, ref} from "vue";
|
|
2
|
+
|
|
3
|
+
import GridSettings from "../settings/GridSettings.js";
|
|
4
|
+
|
|
5
|
+
export const globalGridSettings = ref({});
|
|
6
|
+
export default function useSettings(props) {
|
|
7
|
+
|
|
8
|
+
const localSettingsKeys = ['align', 'disablePagination', 'defaultSlots', 'noDataLabel', 'noCellDataLabel', 'stripped', 'bordered', 'compactPagination', 'rowsPerPageOptions', 'rowsPerPage'];
|
|
9
|
+
|
|
10
|
+
const localSettings = localSettingsKeys.reduce((settings, key) => {
|
|
11
|
+
if (props[key] !== undefined) {
|
|
12
|
+
settings[key] = props[key];
|
|
13
|
+
}
|
|
14
|
+
return settings;
|
|
15
|
+
}, {})
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const settings = computed(() => {
|
|
19
|
+
return {
|
|
20
|
+
...GridSettings,
|
|
21
|
+
...globalGridSettings.value,
|
|
22
|
+
...localSettings
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
settings
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {computed, ref} from 'vue';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export default function useSort(props) {
|
|
5
|
+
|
|
6
|
+
let sortDirection = ref(null);
|
|
7
|
+
let sortFieldType = ref(null);
|
|
8
|
+
let sortField = ref(null);
|
|
9
|
+
// Calculate the next sort direction based on the current field
|
|
10
|
+
const calculateNextSortDirection = function (field) {
|
|
11
|
+
if (sortField.value!==field) {
|
|
12
|
+
return 'ascending'
|
|
13
|
+
} else if (sortDirection.value==='ascending') {
|
|
14
|
+
return 'descending'
|
|
15
|
+
} else {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const setSortFields = function (column, direction = 'auto') {
|
|
21
|
+
if (direction!=='auto') {
|
|
22
|
+
sortField.value = column.name;
|
|
23
|
+
sortFieldType.value = column.type;
|
|
24
|
+
sortDirection.value = direction;
|
|
25
|
+
|
|
26
|
+
} else {
|
|
27
|
+
const nextDirection = calculateNextSortDirection(column.name);
|
|
28
|
+
sortField.value = nextDirection===null ? null:column.name;
|
|
29
|
+
sortFieldType.value = nextDirection===null ? null:column.type;
|
|
30
|
+
sortDirection.value = nextDirection;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
field: sortField.value,
|
|
35
|
+
direction: sortDirection.value
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Format the sort field for use in API requests
|
|
40
|
+
const formatSortFields = () => {
|
|
41
|
+
return sortDirection.value===null ? null:[{
|
|
42
|
+
field: sortField.value,
|
|
43
|
+
descending: sortDirection.value==='descending'
|
|
44
|
+
}];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//sort rows on client side
|
|
48
|
+
const clientSort = function (rows) {
|
|
49
|
+
if (sortDirection.value==='ascending') {
|
|
50
|
+
|
|
51
|
+
return rows.sort((a, b) => {
|
|
52
|
+
return a[sortField.value].toString().localeCompare(b[sortField.value].toString())
|
|
53
|
+
});
|
|
54
|
+
} else if (sortDirection.value==='descending') {
|
|
55
|
+
|
|
56
|
+
return rows.sort((a, b) => b[sortField.value].toString().localeCompare(a[sortField.value].toString()));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return rows;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Set the sort fields from pagination data from API
|
|
63
|
+
const setSortFieldsFromPagination = (pagination) => {
|
|
64
|
+
|
|
65
|
+
if (!pagination?.sortBy?.length) {
|
|
66
|
+
sortField.value = null;
|
|
67
|
+
sortFieldType.value = null;
|
|
68
|
+
sortDirection.value = null;
|
|
69
|
+
} else {
|
|
70
|
+
let column = props.columns.find(column => column.name===pagination.sortBy[0].field);
|
|
71
|
+
setSortFields(column, pagination?.sortBy[0].descending ? 'descending':'ascending');
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Get the sortable state for column based on the current sort state
|
|
76
|
+
const getSortableState = (column) => {
|
|
77
|
+
if (sortField.value!==column.name) {
|
|
78
|
+
return 'unsorted';
|
|
79
|
+
}
|
|
80
|
+
return sortDirection.value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sortedRows = computed(() => {
|
|
84
|
+
if (props.serverMode) {
|
|
85
|
+
return props.rows;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return clientSort([...props.rows])
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
setSortFieldsFromPagination,
|
|
94
|
+
getSortableState,
|
|
95
|
+
setSortFields,
|
|
96
|
+
formatSortFields,
|
|
97
|
+
clientSort,
|
|
98
|
+
sortedRows,
|
|
99
|
+
sortField,
|
|
100
|
+
sortDirection,
|
|
101
|
+
sortFieldType
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,53 +1,77 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<vi-grid-kebab-menu
|
|
2
|
+
<div class="vi-grid-actions" ref="gridActions">
|
|
3
|
+
<vi-grid-kebab-menu
|
|
6
4
|
v-if="kebab"
|
|
7
5
|
:actions="visibleActions"
|
|
8
|
-
|
|
6
|
+
:row-key="rowKey"
|
|
7
|
+
:row="row"
|
|
8
|
+
:show-menu="row[rowKey] === rowMenuOpened"
|
|
9
|
+
@actionClicked="onActionClicked"
|
|
10
|
+
@toggleMenu="$ev => toggleRowMenu(row)"
|
|
9
11
|
/>
|
|
10
|
-
|
|
11
|
-
<vi-grid-builder-actions
|
|
12
|
+
<vi-grid-simple-actions
|
|
12
13
|
v-else
|
|
13
14
|
:actions="visibleActions"
|
|
14
|
-
|
|
15
|
+
:row-key="rowKey"
|
|
16
|
+
:row="row"
|
|
17
|
+
@actionClicked="onActionClicked"
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
/>
|
|
18
|
-
|
|
19
21
|
</div>
|
|
20
22
|
</template>
|
|
21
23
|
|
|
22
24
|
<script>
|
|
23
25
|
import ViGridKebabMenu from "./partials/ViGridKebabMenu.vue";
|
|
24
|
-
import
|
|
26
|
+
import ViGridSimpleActions from "./partials/ViGridSimpleActions.vue";
|
|
25
27
|
|
|
26
28
|
import {useGridActions} from "../composables/useGridActions.js"
|
|
29
|
+
import {onMounted, onUnmounted, ref} from "vue";
|
|
27
30
|
|
|
28
31
|
export default {
|
|
29
32
|
name: "ViGridActions",
|
|
30
|
-
components: {
|
|
33
|
+
components: {ViGridSimpleActions, ViGridKebabMenu},
|
|
31
34
|
props: {
|
|
32
35
|
kebab:{
|
|
33
36
|
type: Boolean,
|
|
34
37
|
default: false,
|
|
35
38
|
},
|
|
36
39
|
row: {},
|
|
40
|
+
rowKey: String,
|
|
37
41
|
actions:{
|
|
38
42
|
type: Array,
|
|
39
43
|
default: function () {
|
|
40
44
|
|
|
41
45
|
return []
|
|
42
46
|
}
|
|
47
|
+
},
|
|
48
|
+
rowMenuOpened:{
|
|
43
49
|
}
|
|
44
50
|
},
|
|
45
51
|
|
|
46
|
-
setup(props) {
|
|
47
|
-
const {visibleActions} = useGridActions(props);
|
|
52
|
+
setup(props, {emit}) {
|
|
53
|
+
const {visibleActions, onActionClicked, toggleRowMenu} = useGridActions(props,emit);
|
|
54
|
+
|
|
48
55
|
|
|
56
|
+
let gridActions = ref(null);
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
gridActions.clickOutsideHandler = (event) => {
|
|
59
|
+
if (props.rowMenuOpened) {
|
|
60
|
+
if (gridActions.value && !(gridActions.value===event.target || gridActions.value.contains(event.target))) {
|
|
61
|
+
emit('update:rowMenuOpened', null);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener('click', gridActions.clickOutsideHandler);
|
|
66
|
+
})
|
|
67
|
+
onUnmounted(() => {
|
|
68
|
+
document.removeEventListener('click', gridActions.clickOutsideHandler);
|
|
69
|
+
})
|
|
49
70
|
return {
|
|
50
71
|
visibleActions,
|
|
72
|
+
onActionClicked,
|
|
73
|
+
toggleRowMenu,
|
|
74
|
+
gridActions
|
|
51
75
|
};
|
|
52
76
|
}
|
|
53
77
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="vi-grid-checkbox">
|
|
3
|
+
<input type="checkbox"
|
|
4
|
+
:checked="value"
|
|
5
|
+
@change="$emit('checkbox-clicked', {row:this.row, field:this.name, value:$event.target.checked})"
|
|
6
|
+
@click.stop
|
|
7
|
+
/>
|
|
8
|
+
</div>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
export default {
|
|
13
|
+
name: "ViGridCheckbox",
|
|
14
|
+
props: {
|
|
15
|
+
value: {
|
|
16
|
+
type: Boolean
|
|
17
|
+
},
|
|
18
|
+
name: {
|
|
19
|
+
type: String
|
|
20
|
+
|
|
21
|
+
},
|
|
22
|
+
row: {
|
|
23
|
+
type: Object
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<style lang="scss">
|
|
30
|
+
@import "ViGridText";
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="vi-grid-number">
|
|
3
|
+
{{value}}
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
name: "ViGridNumber",
|
|
10
|
+
props: {
|
|
11
|
+
value: {},
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<style lang="scss">
|
|
17
|
+
@import "ViGridNumber";
|
|
18
|
+
</style>
|