stk-table-vue 0.8.6 → 0.8.8
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 +2 -1
- package/lib/src/StkTable/StkTable.vue.d.ts +749 -745
- package/lib/src/StkTable/const.d.ts +33 -28
- package/lib/src/StkTable/types/index.d.ts +263 -256
- package/lib/src/StkTable/useVirtualScroll.d.ts +1 -0
- package/lib/stk-table-vue.js +83 -41
- package/lib/style.css +2 -0
- package/package.json +5 -5
- package/src/StkTable/StkTable.vue +46 -21
- package/src/StkTable/const.ts +8 -1
- package/src/StkTable/style.less +2 -0
- package/src/StkTable/types/index.ts +21 -14
- package/src/StkTable/useKeyboardArrowScroll.ts +10 -10
- package/src/StkTable/useVirtualScroll.ts +6 -10
- package/src/StkTable/utils/index.ts +24 -11
|
@@ -67,7 +67,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
67
67
|
rowKeyGen,
|
|
68
68
|
maxRowSpan,
|
|
69
69
|
}: Option<DT>) {
|
|
70
|
-
const tableHeaderHeight =
|
|
70
|
+
const tableHeaderHeight = computed(() => props.headerRowHeight * tableHeaders.value.length);
|
|
71
|
+
|
|
71
72
|
|
|
72
73
|
const virtualScroll = ref<VirtualScrollStore>({
|
|
73
74
|
containerHeight: 0,
|
|
@@ -188,10 +189,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
188
189
|
return rowHeightFn;
|
|
189
190
|
});
|
|
190
191
|
|
|
191
|
-
function getTableHeaderHeight() {
|
|
192
|
-
return props.headerRowHeight * tableHeaders.value.length;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
192
|
/**
|
|
196
193
|
* 初始化虚拟滚动参数
|
|
197
194
|
* @param {number} [height] 虚拟滚动的高度
|
|
@@ -210,18 +207,16 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
210
207
|
console.warn('initVirtualScrollY: height must be a number');
|
|
211
208
|
height = 0;
|
|
212
209
|
}
|
|
213
|
-
const {
|
|
210
|
+
const { clientHeight, scrollHeight } = tableContainerRef.value || {};
|
|
214
211
|
let scrollTop = tableContainerRef.value?.scrollTop || 0;
|
|
215
212
|
|
|
216
213
|
const rowHeight = getRowHeightFn.value();
|
|
217
|
-
const containerHeight = height ||
|
|
214
|
+
const containerHeight = height || clientHeight || DEFAULT_TABLE_HEIGHT;
|
|
218
215
|
const { headless } = props;
|
|
219
216
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
220
|
-
const headerHeight = getTableHeaderHeight();
|
|
221
|
-
tableHeaderHeight.value = headerHeight;
|
|
222
217
|
if (!headless) {
|
|
223
218
|
/** 表头高度占几行表体高度数 */
|
|
224
|
-
const headerToBodyRowHeightCount = Math.floor(
|
|
219
|
+
const headerToBodyRowHeightCount = Math.floor(tableHeaderHeight.value / rowHeight);
|
|
225
220
|
pageSize -= headerToBodyRowHeightCount; //减去表头行数
|
|
226
221
|
}
|
|
227
222
|
const maxScrollTop = dataSourceCopy.value.length * rowHeight + tableHeaderHeight.value - containerHeight;
|
|
@@ -487,6 +482,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
487
482
|
virtualX_on,
|
|
488
483
|
virtualX_columnPart,
|
|
489
484
|
virtualX_offsetRight,
|
|
485
|
+
tableHeaderHeight,
|
|
490
486
|
initVirtualScroll,
|
|
491
487
|
initVirtualScrollY,
|
|
492
488
|
initVirtualScrollX,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CELL_KEY_SEPARATE } from '../const';
|
|
1
|
+
import { CELL_KEY_SEPARATE, DEFAULT_SORT_CONFIG } from '../const';
|
|
2
2
|
import { Order, SortConfig, SortOption, SortState, StkTableColumn, UniqKey } from '../types';
|
|
3
3
|
|
|
4
4
|
/** 是否空值 */
|
|
@@ -158,19 +158,28 @@ export function tableSort<T extends Record<string, any>>(
|
|
|
158
158
|
): T[] {
|
|
159
159
|
if (!dataSource?.length || !sortOption) return dataSource || [];
|
|
160
160
|
|
|
161
|
-
sortConfig = {
|
|
161
|
+
sortConfig = { ...DEFAULT_SORT_CONFIG, ...sortConfig };
|
|
162
162
|
let targetDataSource = dataSource.slice();
|
|
163
163
|
let sortField = sortOption.sortField || sortOption.dataIndex;
|
|
164
|
+
const { defaultSort, stringLocaleCompare, emptyToBottom, sortChildren } = sortConfig;
|
|
164
165
|
|
|
165
|
-
if (!order &&
|
|
166
|
+
if (!order && defaultSort) {
|
|
166
167
|
// 默认排序
|
|
167
|
-
order =
|
|
168
|
-
sortField =
|
|
168
|
+
order = defaultSort.order;
|
|
169
|
+
sortField = defaultSort.dataIndex;
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
if (typeof sortOption.sorter === 'function') {
|
|
172
173
|
const customSorterData = sortOption.sorter(targetDataSource, { order, column: sortOption });
|
|
173
174
|
if (customSorterData) targetDataSource = customSorterData;
|
|
175
|
+
|
|
176
|
+
// 如果开启了子节点排序且使用了自定义排序器,递归排序children
|
|
177
|
+
if (sortChildren) {
|
|
178
|
+
targetDataSource.forEach(item => {
|
|
179
|
+
if (!item.children?.length) return;
|
|
180
|
+
(item as any).children = tableSort(sortOption, order, item.children, sortConfig);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
174
183
|
} else if (order) {
|
|
175
184
|
let { sortType } = sortOption;
|
|
176
185
|
if (!sortType) sortType = typeof dataSource[0][sortField] as 'number' | 'string';
|
|
@@ -179,15 +188,19 @@ export function tableSort<T extends Record<string, any>>(
|
|
|
179
188
|
const [valueArr, emptyArr] = separatedData(sortOption, targetDataSource, isNumber);
|
|
180
189
|
|
|
181
190
|
if (order === 'asc') {
|
|
182
|
-
valueArr.sort((a, b) => strCompare(a[sortField], b[sortField], isNumber,
|
|
191
|
+
valueArr.sort((a, b) => strCompare(a[sortField], b[sortField], isNumber, stringLocaleCompare));
|
|
183
192
|
} else {
|
|
184
|
-
valueArr.sort((a, b) => strCompare(b[sortField], a[sortField], isNumber,
|
|
193
|
+
valueArr.sort((a, b) => strCompare(b[sortField], a[sortField], isNumber, stringLocaleCompare));
|
|
185
194
|
}
|
|
186
195
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
targetDataSource = order === 'desc' || emptyToBottom ? valueArr.concat(emptyArr) : emptyArr.concat(valueArr);
|
|
197
|
+
|
|
198
|
+
// 递归排序子节点
|
|
199
|
+
if (sortChildren) {
|
|
200
|
+
targetDataSource.forEach(item => {
|
|
201
|
+
if (!item.children?.length) return;
|
|
202
|
+
(item as any).children = tableSort(sortOption, order, item.children, sortConfig);
|
|
203
|
+
});
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
206
|
return targetDataSource;
|