funda-ui 4.7.445 → 4.7.512
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/Table/index.js
CHANGED
|
@@ -2069,7 +2069,28 @@ const App = () => {
|
|
|
2069
2069
|
|
|
2070
2070
|
useTableSort({
|
|
2071
2071
|
enabled: sortableTable && rootRef.current,
|
|
2072
|
-
spyElement: rootRef.current
|
|
2072
|
+
spyElement: rootRef.current,
|
|
2073
|
+
sortBy: (handleProcess: Function, filterType: string, inverse: boolean) => (a: Element, b: Element) => {
|
|
2074
|
+
|
|
2075
|
+
// Custom comparison logic
|
|
2076
|
+
let v1 = a.textContent, v2 = b.textContent;
|
|
2077
|
+
if (filterType === 'number') {
|
|
2078
|
+
v1 = parseFloat(v1);
|
|
2079
|
+
v2 = parseFloat(v2);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
let result = 0;
|
|
2083
|
+
if (filterType === 'text') {
|
|
2084
|
+
result = v1.localeCompare(v2);
|
|
2085
|
+
} else {
|
|
2086
|
+
result = v1 - v2;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// Apply display animation and status updates
|
|
2090
|
+
handleProcess();
|
|
2091
|
+
|
|
2092
|
+
return inverse ? -result : result;
|
|
2093
|
+
}
|
|
2073
2094
|
}, [rootRef]);
|
|
2074
2095
|
|
|
2075
2096
|
return (
|
|
@@ -2090,7 +2111,8 @@ function useTableSort(_ref, deps) {
|
|
|
2090
2111
|
_ref$isReverse = _ref.isReverse,
|
|
2091
2112
|
isReverse = _ref$isReverse === void 0 ? false : _ref$isReverse,
|
|
2092
2113
|
onColSort = _ref.onColSort,
|
|
2093
|
-
onClick = _ref.onClick
|
|
2114
|
+
onClick = _ref.onClick,
|
|
2115
|
+
sortBy = _ref.sortBy;
|
|
2094
2116
|
var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
|
|
2095
2117
|
_useState2 = useTableSort_slicedToArray(_useState, 2),
|
|
2096
2118
|
inverse = _useState2[0],
|
|
@@ -2104,16 +2126,22 @@ function useTableSort(_ref, deps) {
|
|
|
2104
2126
|
var filterType = fieldType || 'text';
|
|
2105
2127
|
var curIndex = el.dataset.tableCol;
|
|
2106
2128
|
var targetComparator = [].slice.call(tbodyRef.querySelectorAll("[data-table-col=\"".concat(curIndex, "\"]")));
|
|
2129
|
+
var handleProcess = function handleProcess() {
|
|
2130
|
+
allRows(spyElement).forEach(function (node) {
|
|
2131
|
+
node.classList.add('newsort');
|
|
2132
|
+
});
|
|
2133
|
+
setInverse(!inverse);
|
|
2134
|
+
};
|
|
2107
2135
|
|
|
2108
|
-
//
|
|
2109
|
-
var
|
|
2136
|
+
//
|
|
2137
|
+
var defaultSortBy = function defaultSortBy(a, b) {
|
|
2110
2138
|
var txt1 = a.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase(),
|
|
2111
2139
|
txt2 = b.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase();
|
|
2112
2140
|
|
|
2113
2141
|
//type of number
|
|
2114
2142
|
if (filterType == 'number') {
|
|
2115
|
-
txt1 =
|
|
2116
|
-
txt2 =
|
|
2143
|
+
txt1 = parseFloat(txt1.replace(/[^0-9.+-]+/g, ''));
|
|
2144
|
+
txt2 = parseFloat(txt2.replace(/[^0-9.+-]+/g, ''));
|
|
2117
2145
|
}
|
|
2118
2146
|
|
|
2119
2147
|
//type of date
|
|
@@ -2123,10 +2151,7 @@ function useTableSort(_ref, deps) {
|
|
|
2123
2151
|
}
|
|
2124
2152
|
|
|
2125
2153
|
//add filter class
|
|
2126
|
-
|
|
2127
|
-
node.classList.add('newsort');
|
|
2128
|
-
});
|
|
2129
|
-
setInverse(!inverse);
|
|
2154
|
+
handleProcess();
|
|
2130
2155
|
|
|
2131
2156
|
// result
|
|
2132
2157
|
if (filterType == 'text') {
|
|
@@ -2139,7 +2164,10 @@ function useTableSort(_ref, deps) {
|
|
|
2139
2164
|
return isReverse ? txt1 < txt2 ? -1 : txt1 > txt2 ? 1 : 0 : txt2 < txt1 ? -1 : txt2 > txt1 ? 1 : 0;
|
|
2140
2165
|
}
|
|
2141
2166
|
};
|
|
2142
|
-
|
|
2167
|
+
|
|
2168
|
+
// Use a custom sort method if available, otherwise default is used
|
|
2169
|
+
var sortFn = typeof sortBy === 'function' ? sortBy(handleProcess, filterType, inverse) : defaultSortBy;
|
|
2170
|
+
targetComparator.sort(sortFn);
|
|
2143
2171
|
|
|
2144
2172
|
//console.log( 'targetComparator:', targetComparator );
|
|
2145
2173
|
//console.log( 'inverse:', inverse );
|
|
@@ -2191,7 +2219,8 @@ var SortSprite = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_re
|
|
|
2191
2219
|
icon = props.icon,
|
|
2192
2220
|
_props$isReverse = props.isReverse,
|
|
2193
2221
|
isReverse = _props$isReverse === void 0 ? false : _props$isReverse,
|
|
2194
|
-
onClick = props.onClick
|
|
2222
|
+
onClick = props.onClick,
|
|
2223
|
+
sortBy = props.sortBy;
|
|
2195
2224
|
var _useContext = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(TableContext),
|
|
2196
2225
|
originData = _useContext.originData,
|
|
2197
2226
|
rootRef = _useContext.rootRef,
|
|
@@ -2206,7 +2235,8 @@ var SortSprite = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_re
|
|
|
2206
2235
|
fieldType: fieldType,
|
|
2207
2236
|
onColSort: onColSort,
|
|
2208
2237
|
isReverse: isReverse,
|
|
2209
|
-
onClick: onClick
|
|
2238
|
+
onClick: onClick,
|
|
2239
|
+
sortBy: sortBy
|
|
2210
2240
|
}, [rootRef]),
|
|
2211
2241
|
handleSortList = _useTableSort.handleSortList;
|
|
2212
2242
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, colSortable ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("span", {
|
package/lib/cjs/Table/index.js
CHANGED
|
@@ -2069,7 +2069,28 @@ const App = () => {
|
|
|
2069
2069
|
|
|
2070
2070
|
useTableSort({
|
|
2071
2071
|
enabled: sortableTable && rootRef.current,
|
|
2072
|
-
spyElement: rootRef.current
|
|
2072
|
+
spyElement: rootRef.current,
|
|
2073
|
+
sortBy: (handleProcess: Function, filterType: string, inverse: boolean) => (a: Element, b: Element) => {
|
|
2074
|
+
|
|
2075
|
+
// Custom comparison logic
|
|
2076
|
+
let v1 = a.textContent, v2 = b.textContent;
|
|
2077
|
+
if (filterType === 'number') {
|
|
2078
|
+
v1 = parseFloat(v1);
|
|
2079
|
+
v2 = parseFloat(v2);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
let result = 0;
|
|
2083
|
+
if (filterType === 'text') {
|
|
2084
|
+
result = v1.localeCompare(v2);
|
|
2085
|
+
} else {
|
|
2086
|
+
result = v1 - v2;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// Apply display animation and status updates
|
|
2090
|
+
handleProcess();
|
|
2091
|
+
|
|
2092
|
+
return inverse ? -result : result;
|
|
2093
|
+
}
|
|
2073
2094
|
}, [rootRef]);
|
|
2074
2095
|
|
|
2075
2096
|
return (
|
|
@@ -2090,7 +2111,8 @@ function useTableSort(_ref, deps) {
|
|
|
2090
2111
|
_ref$isReverse = _ref.isReverse,
|
|
2091
2112
|
isReverse = _ref$isReverse === void 0 ? false : _ref$isReverse,
|
|
2092
2113
|
onColSort = _ref.onColSort,
|
|
2093
|
-
onClick = _ref.onClick
|
|
2114
|
+
onClick = _ref.onClick,
|
|
2115
|
+
sortBy = _ref.sortBy;
|
|
2094
2116
|
var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
|
|
2095
2117
|
_useState2 = useTableSort_slicedToArray(_useState, 2),
|
|
2096
2118
|
inverse = _useState2[0],
|
|
@@ -2104,16 +2126,22 @@ function useTableSort(_ref, deps) {
|
|
|
2104
2126
|
var filterType = fieldType || 'text';
|
|
2105
2127
|
var curIndex = el.dataset.tableCol;
|
|
2106
2128
|
var targetComparator = [].slice.call(tbodyRef.querySelectorAll("[data-table-col=\"".concat(curIndex, "\"]")));
|
|
2129
|
+
var handleProcess = function handleProcess() {
|
|
2130
|
+
allRows(spyElement).forEach(function (node) {
|
|
2131
|
+
node.classList.add('newsort');
|
|
2132
|
+
});
|
|
2133
|
+
setInverse(!inverse);
|
|
2134
|
+
};
|
|
2107
2135
|
|
|
2108
|
-
//
|
|
2109
|
-
var
|
|
2136
|
+
//
|
|
2137
|
+
var defaultSortBy = function defaultSortBy(a, b) {
|
|
2110
2138
|
var txt1 = a.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase(),
|
|
2111
2139
|
txt2 = b.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase();
|
|
2112
2140
|
|
|
2113
2141
|
//type of number
|
|
2114
2142
|
if (filterType == 'number') {
|
|
2115
|
-
txt1 =
|
|
2116
|
-
txt2 =
|
|
2143
|
+
txt1 = parseFloat(txt1.replace(/[^0-9.+-]+/g, ''));
|
|
2144
|
+
txt2 = parseFloat(txt2.replace(/[^0-9.+-]+/g, ''));
|
|
2117
2145
|
}
|
|
2118
2146
|
|
|
2119
2147
|
//type of date
|
|
@@ -2123,10 +2151,7 @@ function useTableSort(_ref, deps) {
|
|
|
2123
2151
|
}
|
|
2124
2152
|
|
|
2125
2153
|
//add filter class
|
|
2126
|
-
|
|
2127
|
-
node.classList.add('newsort');
|
|
2128
|
-
});
|
|
2129
|
-
setInverse(!inverse);
|
|
2154
|
+
handleProcess();
|
|
2130
2155
|
|
|
2131
2156
|
// result
|
|
2132
2157
|
if (filterType == 'text') {
|
|
@@ -2139,7 +2164,10 @@ function useTableSort(_ref, deps) {
|
|
|
2139
2164
|
return isReverse ? txt1 < txt2 ? -1 : txt1 > txt2 ? 1 : 0 : txt2 < txt1 ? -1 : txt2 > txt1 ? 1 : 0;
|
|
2140
2165
|
}
|
|
2141
2166
|
};
|
|
2142
|
-
|
|
2167
|
+
|
|
2168
|
+
// Use a custom sort method if available, otherwise default is used
|
|
2169
|
+
var sortFn = typeof sortBy === 'function' ? sortBy(handleProcess, filterType, inverse) : defaultSortBy;
|
|
2170
|
+
targetComparator.sort(sortFn);
|
|
2143
2171
|
|
|
2144
2172
|
//console.log( 'targetComparator:', targetComparator );
|
|
2145
2173
|
//console.log( 'inverse:', inverse );
|
|
@@ -2191,7 +2219,8 @@ var SortSprite = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_re
|
|
|
2191
2219
|
icon = props.icon,
|
|
2192
2220
|
_props$isReverse = props.isReverse,
|
|
2193
2221
|
isReverse = _props$isReverse === void 0 ? false : _props$isReverse,
|
|
2194
|
-
onClick = props.onClick
|
|
2222
|
+
onClick = props.onClick,
|
|
2223
|
+
sortBy = props.sortBy;
|
|
2195
2224
|
var _useContext = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(TableContext),
|
|
2196
2225
|
originData = _useContext.originData,
|
|
2197
2226
|
rootRef = _useContext.rootRef,
|
|
@@ -2206,7 +2235,8 @@ var SortSprite = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_re
|
|
|
2206
2235
|
fieldType: fieldType,
|
|
2207
2236
|
onColSort: onColSort,
|
|
2208
2237
|
isReverse: isReverse,
|
|
2209
|
-
onClick: onClick
|
|
2238
|
+
onClick: onClick,
|
|
2239
|
+
sortBy: sortBy
|
|
2210
2240
|
}, [rootRef]),
|
|
2211
2241
|
handleSortList = _useTableSort.handleSortList;
|
|
2212
2242
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, colSortable ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("span", {
|
|
@@ -9,6 +9,7 @@ export type SortSpriteProps = {
|
|
|
9
9
|
icon?: React.ReactNode;
|
|
10
10
|
isReverse?: boolean;
|
|
11
11
|
onClick?: (e: any) => void;
|
|
12
|
+
sortBy?: (handleProcess: Function, filterType: string, inverse: boolean) => ((a: Element, b: Element) => number); // A function that determines the order of the elements.
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
|
|
@@ -18,7 +19,8 @@ const SortSprite = forwardRef((props: SortSpriteProps, externalRef: any) => {
|
|
|
18
19
|
className,
|
|
19
20
|
icon,
|
|
20
21
|
isReverse = false,
|
|
21
|
-
onClick
|
|
22
|
+
onClick,
|
|
23
|
+
sortBy
|
|
22
24
|
} = props;
|
|
23
25
|
|
|
24
26
|
const {
|
|
@@ -37,7 +39,8 @@ const SortSprite = forwardRef((props: SortSpriteProps, externalRef: any) => {
|
|
|
37
39
|
fieldType: fieldType,
|
|
38
40
|
onColSort: onColSort,
|
|
39
41
|
isReverse: isReverse,
|
|
40
|
-
onClick: onClick
|
|
42
|
+
onClick: onClick,
|
|
43
|
+
sortBy: sortBy
|
|
41
44
|
}, [rootRef]);
|
|
42
45
|
|
|
43
46
|
|
|
@@ -10,7 +10,28 @@ const App = () => {
|
|
|
10
10
|
|
|
11
11
|
useTableSort({
|
|
12
12
|
enabled: sortableTable && rootRef.current,
|
|
13
|
-
spyElement: rootRef.current
|
|
13
|
+
spyElement: rootRef.current,
|
|
14
|
+
sortBy: (handleProcess: Function, filterType: string, inverse: boolean) => (a: Element, b: Element) => {
|
|
15
|
+
|
|
16
|
+
// Custom comparison logic
|
|
17
|
+
let v1 = a.textContent, v2 = b.textContent;
|
|
18
|
+
if (filterType === 'number') {
|
|
19
|
+
v1 = parseFloat(v1);
|
|
20
|
+
v2 = parseFloat(v2);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let result = 0;
|
|
24
|
+
if (filterType === 'text') {
|
|
25
|
+
result = v1.localeCompare(v2);
|
|
26
|
+
} else {
|
|
27
|
+
result = v1 - v2;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Apply display animation and status updates
|
|
31
|
+
handleProcess();
|
|
32
|
+
|
|
33
|
+
return inverse ? -result : result;
|
|
34
|
+
}
|
|
14
35
|
}, [rootRef]);
|
|
15
36
|
|
|
16
37
|
return (
|
|
@@ -25,6 +46,7 @@ import { useEffect, useState } from 'react';
|
|
|
25
46
|
|
|
26
47
|
import { getTbody, allRows, sortDataByIndex, initOrderProps, initRowColProps } from '../func';
|
|
27
48
|
|
|
49
|
+
|
|
28
50
|
export interface UseTableSortProps {
|
|
29
51
|
enabled: boolean;
|
|
30
52
|
data?: any[];
|
|
@@ -33,6 +55,7 @@ export interface UseTableSortProps {
|
|
|
33
55
|
isReverse?: boolean;
|
|
34
56
|
onColSort?: (fetchData: any) => void;
|
|
35
57
|
onClick?: (e: any) => void;
|
|
58
|
+
sortBy?: (handleProcess: Function, filterType: string, inverse: boolean) => ((a: Element, b: Element) => number); // A function that determines the order of the elements.
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
function useTableSort({
|
|
@@ -42,7 +65,8 @@ function useTableSort({
|
|
|
42
65
|
fieldType,
|
|
43
66
|
isReverse = false,
|
|
44
67
|
onColSort,
|
|
45
|
-
onClick
|
|
68
|
+
onClick,
|
|
69
|
+
sortBy
|
|
46
70
|
}: UseTableSortProps, deps: any[]) {
|
|
47
71
|
|
|
48
72
|
|
|
@@ -62,17 +86,24 @@ function useTableSort({
|
|
|
62
86
|
const curIndex = el.dataset.tableCol;
|
|
63
87
|
const targetComparator = [].slice.call(tbodyRef.querySelectorAll(`[data-table-col="${curIndex}"]`));
|
|
64
88
|
|
|
89
|
+
const handleProcess = function () {
|
|
90
|
+
allRows(spyElement).forEach((node: any) => {
|
|
91
|
+
node.classList.add('newsort');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
setInverse(!inverse);
|
|
95
|
+
};
|
|
65
96
|
|
|
66
|
-
//
|
|
67
|
-
const
|
|
97
|
+
//
|
|
98
|
+
const defaultSortBy = function (a: Element, b: Element) {
|
|
68
99
|
|
|
69
|
-
let txt1 = a.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase(),
|
|
70
|
-
txt2 = b.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase();
|
|
100
|
+
let txt1: any = a.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase(),
|
|
101
|
+
txt2: any = b.innerHTML.replace(/(<([^>]+)>)/ig, '').toLowerCase();
|
|
71
102
|
|
|
72
103
|
//type of number
|
|
73
104
|
if (filterType == 'number') {
|
|
74
|
-
txt1 =
|
|
75
|
-
txt2 =
|
|
105
|
+
txt1 = parseFloat(txt1.replace(/[^0-9.+-]+/g, ''));
|
|
106
|
+
txt2 = parseFloat(txt2.replace(/[^0-9.+-]+/g, ''));
|
|
76
107
|
}
|
|
77
108
|
|
|
78
109
|
//type of date
|
|
@@ -83,14 +114,9 @@ function useTableSort({
|
|
|
83
114
|
|
|
84
115
|
|
|
85
116
|
//add filter class
|
|
86
|
-
|
|
87
|
-
node.classList.add('newsort');
|
|
88
|
-
});
|
|
117
|
+
handleProcess();
|
|
89
118
|
|
|
90
119
|
|
|
91
|
-
setInverse(!inverse);
|
|
92
|
-
|
|
93
|
-
|
|
94
120
|
// result
|
|
95
121
|
if (filterType == 'text') {
|
|
96
122
|
return isReverse
|
|
@@ -104,7 +130,10 @@ function useTableSort({
|
|
|
104
130
|
|
|
105
131
|
}
|
|
106
132
|
|
|
107
|
-
|
|
133
|
+
// Use a custom sort method if available, otherwise default is used
|
|
134
|
+
const sortFn = typeof sortBy === 'function' ? sortBy(handleProcess, filterType, inverse) : defaultSortBy;
|
|
135
|
+
|
|
136
|
+
targetComparator.sort(sortFn);
|
|
108
137
|
|
|
109
138
|
//console.log( 'targetComparator:', targetComparator );
|
|
110
139
|
//console.log( 'inverse:', inverse );
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "UIUX Lab",
|
|
3
3
|
"email": "uiuxlab@gmail.com",
|
|
4
4
|
"name": "funda-ui",
|
|
5
|
-
"version": "4.7.
|
|
5
|
+
"version": "4.7.512",
|
|
6
6
|
"description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|