@etsoo/materialui 1.3.10 → 1.3.11
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/lib/MUUtils.d.ts +8 -0
- package/lib/MUUtils.js +23 -0
- package/package.json +1 -1
- package/src/MUUtils.ts +29 -0
package/lib/MUUtils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListType2 } from "@etsoo/shared";
|
|
2
|
+
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
3
|
/**
|
|
3
4
|
* MU utilities
|
|
4
5
|
*/
|
|
@@ -9,4 +10,11 @@ export declare namespace MUUtils {
|
|
|
9
10
|
* @returns Result
|
|
10
11
|
*/
|
|
11
12
|
function getListItemLabel(item: ListType2): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get grid data
|
|
15
|
+
* @param grid Grid
|
|
16
|
+
* @param checkField Check field or callback
|
|
17
|
+
* @returns Results
|
|
18
|
+
*/
|
|
19
|
+
function getGridData<T>(grid: GridApiCommunity, checkField: keyof T | ((item: T) => boolean)): T[];
|
|
12
20
|
}
|
package/lib/MUUtils.js
CHANGED
|
@@ -16,4 +16,27 @@ export var MUUtils;
|
|
|
16
16
|
: item.title;
|
|
17
17
|
}
|
|
18
18
|
MUUtils.getListItemLabel = getListItemLabel;
|
|
19
|
+
/**
|
|
20
|
+
* Get grid data
|
|
21
|
+
* @param grid Grid
|
|
22
|
+
* @param checkField Check field or callback
|
|
23
|
+
* @returns Results
|
|
24
|
+
*/
|
|
25
|
+
function getGridData(grid, checkField) {
|
|
26
|
+
const check = typeof checkField === "function"
|
|
27
|
+
? checkField
|
|
28
|
+
: (item) => {
|
|
29
|
+
const value = item[checkField];
|
|
30
|
+
return value == null || value === "" ? false : true;
|
|
31
|
+
};
|
|
32
|
+
const items = [];
|
|
33
|
+
for (const [_, value] of grid.getRowModels()) {
|
|
34
|
+
const item = value;
|
|
35
|
+
if (check(item)) {
|
|
36
|
+
items.push(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return items;
|
|
40
|
+
}
|
|
41
|
+
MUUtils.getGridData = getGridData;
|
|
19
42
|
})(MUUtils || (MUUtils = {}));
|
package/package.json
CHANGED
package/src/MUUtils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListType2 } from "@etsoo/shared";
|
|
2
|
+
import { GridApiCommunity } from "@mui/x-data-grid/models/api/gridApiCommunity";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* MU utilities
|
|
@@ -16,4 +17,32 @@ export namespace MUUtils {
|
|
|
16
17
|
? item.name
|
|
17
18
|
: item.title;
|
|
18
19
|
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get grid data
|
|
23
|
+
* @param grid Grid
|
|
24
|
+
* @param checkField Check field or callback
|
|
25
|
+
* @returns Results
|
|
26
|
+
*/
|
|
27
|
+
export function getGridData<T>(
|
|
28
|
+
grid: GridApiCommunity,
|
|
29
|
+
checkField: keyof T | ((item: T) => boolean)
|
|
30
|
+
) {
|
|
31
|
+
const check =
|
|
32
|
+
typeof checkField === "function"
|
|
33
|
+
? checkField
|
|
34
|
+
: (item: T) => {
|
|
35
|
+
const value = item[checkField];
|
|
36
|
+
return value == null || value === "" ? false : true;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const items: T[] = [];
|
|
40
|
+
for (const [_, value] of grid.getRowModels()) {
|
|
41
|
+
const item = value as T;
|
|
42
|
+
if (check(item)) {
|
|
43
|
+
items.push(item);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return items;
|
|
47
|
+
}
|
|
19
48
|
}
|