mui-datatables-updated 1.0.1 → 1.0.3
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/LICENSE +21 -21
- package/README.md +185 -175
- package/dist/components/MUITable.d.ts +4 -3
- package/dist/components/TableHead.d.ts +2 -2
- package/dist/components/Toolbar.d.ts +3 -3
- package/dist/components/utils.d.ts +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +112 -65
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +112 -65
- package/dist/index.js.map +1 -1
- package/dist/tests/MUITable.performance.test.d.ts +1 -0
- package/dist/tests/MUITable.test.d.ts +1 -0
- package/dist/tests/setup.d.ts +1 -0
- package/dist/tests/test-data.d.ts +2 -2
- package/dist/tests/utils.test.d.ts +1 -0
- package/package.json +82 -58
- package/dist/components/table.d.ts +0 -1
- package/dist/components/test-data.d.ts +0 -11
- package/rollup.config.mjs +0 -23
- package/src/components/MUITable.tsx +0 -344
- package/src/components/TableHead.tsx +0 -81
- package/src/components/Toolbar.tsx +0 -340
- package/src/components/utils.ts +0 -17
- package/src/index.ts +0 -3
- package/tsconfig.json +0 -24
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Diego Jacobo Martínez
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Diego Jacobo Martínez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,175 +1,185 @@
|
|
|
1
|
-
# MUI Datatable library inspired by the gregnb/mui-datatables project, featuring an up-to-date implementation with Typescript Support
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: '
|
|
70
|
-
label: '
|
|
71
|
-
options: {
|
|
72
|
-
sort: false
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
| Name | Type | Description |
|
|
129
|
-
| --- | --- | --- |
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
134
|
-
###
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
1
|
+
# MUI Datatable library inspired by the gregnb/mui-datatables project, featuring an up-to-date implementation with Typescript Support
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
If not already installed, install the Material-UI library:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then install the mui-datatables-updated package along with its peer dependencies:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install mui-datatables-updated react-to-print
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import { MUITable } from 'mui-datatables-updated';
|
|
22
|
+
|
|
23
|
+
const sampleData = [
|
|
24
|
+
{
|
|
25
|
+
"id": 1,
|
|
26
|
+
"name": "Cupcake",
|
|
27
|
+
"carbs": 67,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": 2,
|
|
31
|
+
"name": "Donut",
|
|
32
|
+
"carbs": 51,
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export default function App() {
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<MUITable title='Sample title' data={sampleData} />
|
|
40
|
+
</>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
| Name | Type | Description |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| title | string | Title of the table |
|
|
50
|
+
| data | array | Data to be displayed in the table |
|
|
51
|
+
| deactivateSelect | boolean | Disable row selection |
|
|
52
|
+
| defaultOrderBy | string -> must be a key in the data object | Default order by key to sort the table data on first load |
|
|
53
|
+
| defaultOrder | 'asc' or 'desc' | Default order to be used when sorting and displaying on first load |
|
|
54
|
+
| excludedColumns | array | Array of **keys** in data objects to be excluded from the table |
|
|
55
|
+
| columns | array | Array of objects to define the columns of the table |
|
|
56
|
+
| options | object | Object to define the options of the table |
|
|
57
|
+
|
|
58
|
+
### Example
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
import { MUITable } from 'mui-datatables-updated';
|
|
62
|
+
|
|
63
|
+
const sampleColumns = [
|
|
64
|
+
{
|
|
65
|
+
name: 'name',
|
|
66
|
+
label: 'Name of dessert',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'healthy',
|
|
70
|
+
label: 'Is Healthy?',
|
|
71
|
+
options: {
|
|
72
|
+
sort: false,
|
|
73
|
+
customBodyRender: (value: boolean) => value ? ':)' : ':('
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'carbs',
|
|
78
|
+
label: 'Carbs (g)',
|
|
79
|
+
options: {
|
|
80
|
+
sort: false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'id',
|
|
85
|
+
label: 'ID',
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
function App() {
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<h1>MUI Table test</h1>
|
|
93
|
+
<MUITable
|
|
94
|
+
title='Sample Test'
|
|
95
|
+
data={sampleData}
|
|
96
|
+
defaultOrder='desc'
|
|
97
|
+
defaultOrderBy='name'
|
|
98
|
+
excludedColumns={['id']}
|
|
99
|
+
/>
|
|
100
|
+
<MUITable
|
|
101
|
+
title='Sample Test'
|
|
102
|
+
data={sampleData}
|
|
103
|
+
defaultOrder='desc'
|
|
104
|
+
defaultOrderBy='name'
|
|
105
|
+
columns={sampleColumns}
|
|
106
|
+
deactivateSelect
|
|
107
|
+
options={{
|
|
108
|
+
translations: {
|
|
109
|
+
filterTooltip: 'Filtrar',
|
|
110
|
+
filtersTitle: 'Filtros',
|
|
111
|
+
resetButtonText: 'Reiniciar',
|
|
112
|
+
searchPlaceholder: 'Buscar...',
|
|
113
|
+
rowsPerPageText: 'Filas por página',
|
|
114
|
+
selectedTextRenderer: (numSelected) => `${numSelected} seleccionado/s`,
|
|
115
|
+
labelDisplayedRows: ({ from, to, count }) => `${from}-${to} de ${count}`,
|
|
116
|
+
}
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
</>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Custom Columns
|
|
125
|
+
|
|
126
|
+
On each column object, you have the ability to customize columns to show the filtering options in the filter dropdown and to disable sorting when clicking on the column header. Values are set to true by default.
|
|
127
|
+
|
|
128
|
+
| Name | Type | Description |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| name | string | Key in the data object |
|
|
131
|
+
| label | string | Label to be displayed in the column header |
|
|
132
|
+
| options | object | Object to define the options of the column |
|
|
133
|
+
|
|
134
|
+
### Options Object
|
|
135
|
+
|
|
136
|
+
| Name | Type | Description |
|
|
137
|
+
| --- | --- | --- |
|
|
138
|
+
| customBodyRender | function | Function to render custom content in the column |
|
|
139
|
+
| customSearchValue | function | Function to provide searchable text/value for global search (useful with customBodyRender) |
|
|
140
|
+
| filter | boolean | Show filter dropdown in the column |
|
|
141
|
+
| sort | boolean | Enable sorting when clicking on the column header |
|
|
142
|
+
|
|
143
|
+
### Custom columns example
|
|
144
|
+
|
|
145
|
+
```jsx
|
|
146
|
+
const columns = [
|
|
147
|
+
{
|
|
148
|
+
name: "active",
|
|
149
|
+
label: "Is Active",
|
|
150
|
+
options: {
|
|
151
|
+
customBodyRender: (value: boolean) => value ? 'Yes' : 'No',
|
|
152
|
+
customSearchValue: (value: boolean) => value ? 'Yes' : 'No',
|
|
153
|
+
filter: true,
|
|
154
|
+
sort: false
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
...
|
|
158
|
+
];
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Localization
|
|
162
|
+
|
|
163
|
+
As well as gregnb original package, I decided that the cost of bringing in another library to perform localizations would be too expensive. Instead the ability to override most text labels (which aren't many) is offered through the translations property. The available customizations are:
|
|
164
|
+
|
|
165
|
+
```jsx
|
|
166
|
+
<MUITable
|
|
167
|
+
title='Sample Test'
|
|
168
|
+
data={sampleData}
|
|
169
|
+
options={{
|
|
170
|
+
translations: {
|
|
171
|
+
filterTooltip: 'Filtrar',
|
|
172
|
+
filtersTitle: 'Filtros',
|
|
173
|
+
resetButtonText: 'Reiniciar',
|
|
174
|
+
searchPlaceholder: 'Buscar...',
|
|
175
|
+
rowsPerPageText: 'Filas por página',
|
|
176
|
+
selectedTextRenderer: (numSelected) => `${numSelected} seleccionado/s`,
|
|
177
|
+
labelDisplayedRows: ({ from, to, count }) => `${from}-${to} de ${count}`,
|
|
178
|
+
}
|
|
179
|
+
}}
|
|
180
|
+
/>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
Pull requests are welcome. I won't be able to implement new features in the short term, so feel free to contribute to the project by adding new features, fixing bugs, creating tests, and improving the documentation.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { CustomSelectedToolbarProps } from './Toolbar';
|
|
3
|
-
import { Order } from './utils';
|
|
4
|
-
import { LabelDisplayedRowsArgs } from '@mui/material/TablePagination';
|
|
2
|
+
import { type CustomSelectedToolbarProps } from './Toolbar';
|
|
3
|
+
import { type Order } from './utils';
|
|
4
|
+
import type { LabelDisplayedRowsArgs } from '@mui/material/TablePagination';
|
|
5
5
|
export interface Column {
|
|
6
6
|
name: string;
|
|
7
7
|
label?: string;
|
|
8
8
|
options?: {
|
|
9
9
|
customBodyRender?: (value: any) => React.ReactNode;
|
|
10
|
+
customSearchValue?: (value: any, row: Record<string, any>) => unknown;
|
|
10
11
|
filter?: boolean;
|
|
11
12
|
sort?: boolean;
|
|
12
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Column } from './MUITable';
|
|
2
|
-
import { Order } from './utils';
|
|
1
|
+
import type { Column } from './MUITable';
|
|
2
|
+
import type { Order } from './utils';
|
|
3
3
|
interface EnhancedTableProps<T> {
|
|
4
4
|
numSelected: number;
|
|
5
5
|
onRequestSort: (event: React.MouseEvent<unknown>, property: keyof T) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Column, Options } from "./MUITable";
|
|
3
|
-
import { UseReactToPrintFn } from "react-to-print";
|
|
2
|
+
import type { Column, Options } from "./MUITable";
|
|
3
|
+
import type { UseReactToPrintFn } from "react-to-print";
|
|
4
4
|
export interface CustomSelectedToolbarProps<T> {
|
|
5
5
|
selected?: readonly T[];
|
|
6
6
|
data?: T[];
|
|
@@ -18,5 +18,5 @@ interface EnhancedTableToolbarProps<T> {
|
|
|
18
18
|
data?: T[];
|
|
19
19
|
options?: Options;
|
|
20
20
|
}
|
|
21
|
-
export declare function EnhancedTableToolbar<T>(props: EnhancedTableToolbarProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function EnhancedTableToolbar<T extends object>(props: EnhancedTableToolbarProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
22
22
|
export {};
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export type Order = 'asc' | 'desc';
|
|
2
|
+
export interface SearchColumn<T extends object> {
|
|
3
|
+
name: string;
|
|
4
|
+
options?: {
|
|
5
|
+
customBodyRender?: (value: any) => unknown;
|
|
6
|
+
customSearchValue?: (value: any, row: Record<string, any>) => unknown;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
2
9
|
export declare function getComparator<T, Key extends keyof T>(order: Order, orderBy: Key): (a: T, b: T) => number;
|
|
10
|
+
export declare function toSearchTokens(value: unknown): string[];
|
|
11
|
+
export declare function getColumnSearchTokens<T extends object>(row: T, column: SearchColumn<T>): string[];
|
|
12
|
+
export declare function columnMatchesSearchQuery<T extends object>(row: T, column: SearchColumn<T>, searchQuery: string): boolean;
|
|
13
|
+
export declare function rowMatchesSearchQuery<T extends object>(row: T, columns: SearchColumn<T>[], searchQuery: string): boolean;
|
package/dist/index.d.ts
CHANGED