quasar-ui-danx 0.3.25 → 0.3.26
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/danx.es.js +2 -1
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +1 -1
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/tableColumns.ts +65 -64
package/package.json
CHANGED
@@ -2,81 +2,82 @@ import { computed, ref, watch } from "vue";
|
|
2
2
|
import { getItem, setItem } from "../../helpers";
|
3
3
|
|
4
4
|
export interface TableColumn {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
5
|
+
actionMenu?: object,
|
6
|
+
align?: string,
|
7
|
+
category?: string,
|
8
|
+
class?: string | object,
|
9
|
+
field: string,
|
10
|
+
format?: Function,
|
11
|
+
innerClass?: string | object,
|
12
|
+
style?: string | object,
|
13
|
+
headerStyle?: string | object,
|
14
|
+
isSavingRow?: boolean | Function,
|
15
|
+
label: string,
|
16
|
+
maxWidth?: number,
|
17
|
+
minWidth?: number,
|
18
|
+
name: string,
|
19
|
+
onClick?: Function,
|
20
|
+
required?: boolean,
|
21
|
+
resizeable?: boolean,
|
22
|
+
sortable?: boolean,
|
23
|
+
sortBy?: string,
|
24
|
+
sortByExpression?: string,
|
25
|
+
titleColumns?: Function,
|
26
|
+
vnode?: Function,
|
27
27
|
}
|
28
28
|
|
29
29
|
export function useTableColumns(name: string, columns: TableColumn[]) {
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
const COLUMN_ORDER_KEY = `${name}-column-order`;
|
31
|
+
const VISIBLE_COLUMNS_KEY = `${name}-visible-columns`;
|
32
|
+
const TITLE_COLUMNS_KEY = `${name}-title-columns`;
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
// The list that defines the order the columns should appear in
|
35
|
+
const columnOrder = ref(getItem(COLUMN_ORDER_KEY) || []);
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
// Manages visible columns on the table
|
38
|
+
const hiddenColumnNames = ref(getItem(VISIBLE_COLUMNS_KEY, []));
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
// Title columns will have their name appear on the first column of the table as part of the records' title
|
41
|
+
const titleColumnNames = ref(getItem(TITLE_COLUMNS_KEY, []));
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
// Columns that should be locked to the left side of the table
|
44
|
+
const lockedColumns = computed(() => orderedColumns.value.slice(0, 1));
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
// The resolved list of columns in the order they should appear in
|
47
|
+
const orderedColumns = computed(() => [...columns].sort((a, b) => {
|
48
|
+
const aIndex = columnOrder.value.indexOf(a.name);
|
49
|
+
const bIndex = columnOrder.value.indexOf(b.name);
|
50
|
+
return aIndex === -1 ? 1 : bIndex === -1 ? -1 : aIndex - bIndex;
|
51
|
+
}));
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
// The ordered list of columns. The ordering of this list is editable and will be stored in localStorage
|
54
|
+
const sortableColumns = computed({
|
55
|
+
get() {
|
56
|
+
return orderedColumns.value.slice(1);
|
57
|
+
},
|
58
|
+
set(newColumns) {
|
59
|
+
columnOrder.value = [...lockedColumns.value.map(c => c.name), ...newColumns.map(c => c.name)];
|
60
|
+
setItem(COLUMN_ORDER_KEY, columnOrder.value);
|
61
|
+
}
|
62
|
+
});
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
// The list of columns that are visible. To edit the visible columns, edit the hiddenColumnNames list
|
65
|
+
const visibleColumns = computed(() => orderedColumns.value.filter(c => !hiddenColumnNames.value.includes(c.name)));
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
// The list of columns that should be included in the title of a row
|
68
|
+
const orderedTitleColumns = computed(() => orderedColumns.value.filter(c => titleColumnNames.value.includes(c.name)));
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
// Save changes to the list of hidden columns in localStorage
|
71
|
+
watch(() => hiddenColumnNames.value, () => setItem(VISIBLE_COLUMNS_KEY, hiddenColumnNames.value));
|
72
|
+
watch(() => titleColumnNames.value, () => setItem(TITLE_COLUMNS_KEY, titleColumnNames.value));
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
return {
|
75
|
+
sortableColumns,
|
76
|
+
lockedColumns,
|
77
|
+
visibleColumns,
|
78
|
+
hiddenColumnNames,
|
79
|
+
columnOrder,
|
80
|
+
titleColumnNames,
|
81
|
+
orderedTitleColumns
|
82
|
+
};
|
82
83
|
}
|