@massimo-cassandro/minimo 1.29.1 → 1.29.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/package.json +1 -1
- package/src/web-components/s-datatable-component/docs.md +484 -0
- package/src/web-components/s-datatable-component/s-datatable-component.js +1210 -0
- package/src/web-components/s-datatable-component/s-datatable-component.module.css +220 -0
- package/src/web-components/s-datatable-component/simple-datatable.minimo.tokens.mjs +47 -0
- package/src/web-components/s-datatable-component/src/parse-cols.js +158 -0
- package/src/web-components/s-datatable-component/src/search-method.js +84 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
|
|
2
|
+
/* frontend/src/web-components/s-datatable-component.module.css */
|
|
3
|
+
|
|
4
|
+
/* import delle custom properties gestito da jit-props */
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/* purgecss start ignore */
|
|
8
|
+
|
|
9
|
+
/* .datatable-wrapper.no-header .datatable-container {
|
|
10
|
+
border-top: 1px solid #d9d9d9;
|
|
11
|
+
} */
|
|
12
|
+
.datatableWrapper {
|
|
13
|
+
margin-block: var(--size-md);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.topArea {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-flow: row nowrap;
|
|
19
|
+
gap: 2rem;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: flex-end;
|
|
22
|
+
padding-block-end: var(--size-xs);
|
|
23
|
+
|
|
24
|
+
/* stylelint-disable-next-line selector-class-pattern */
|
|
25
|
+
&:has(.info), &:has(:global(.datatable-top-slot)) {
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.searchWrapper {
|
|
31
|
+
max-width: 50%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.table {
|
|
35
|
+
margin-block: 0;
|
|
36
|
+
border-block: var(--_border); /* definito in minimo table */
|
|
37
|
+
|
|
38
|
+
thead {
|
|
39
|
+
th:has(.sortBtn) {
|
|
40
|
+
padding-inline-end: 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* cella unica per indicare l'assenza di record */
|
|
47
|
+
.empty {
|
|
48
|
+
/* stylelint-disable-next-line declaration-no-important */
|
|
49
|
+
padding-block: var(--size-sm) !important;
|
|
50
|
+
font-style: italic;
|
|
51
|
+
color: var(--text-muted);
|
|
52
|
+
/* stylelint-disable-next-line declaration-no-important */
|
|
53
|
+
text-align: center !important;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.hasIcon {
|
|
57
|
+
/* stylelint-disable-next-line declaration-no-important */
|
|
58
|
+
text-align: center !important;
|
|
59
|
+
svg {
|
|
60
|
+
display: inline-block;
|
|
61
|
+
width: 1.05em;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
[data-sortable='true'] {
|
|
67
|
+
|
|
68
|
+
@media (hover: hover) {
|
|
69
|
+
&:hover {
|
|
70
|
+
background-color: var(--sdt-thead-hover-background-color);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.sortBtn {
|
|
75
|
+
padding: 0 1.5em 0 0;
|
|
76
|
+
&::after {
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 50%;
|
|
79
|
+
right: .1em;
|
|
80
|
+
display: block;
|
|
81
|
+
width: 1em;
|
|
82
|
+
height: 1em;
|
|
83
|
+
translate: 0 -50%;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&:not(.sortAscending):not(.sortDescending){
|
|
88
|
+
.sortBtn::after {
|
|
89
|
+
content: url('../../icons/arrows-down-up.svg?cssInline');
|
|
90
|
+
opacity: .4;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
.sortAscending {
|
|
95
|
+
.sortBtn::after {
|
|
96
|
+
content: url('../../icons/arrow-up.svg?cssInline');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
.sortDescending {
|
|
100
|
+
.sortBtn::after {
|
|
101
|
+
content: url('../../icons/arrow-down.svg?cssInline');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.sortBtn {
|
|
106
|
+
position: relative;
|
|
107
|
+
display: block;
|
|
108
|
+
width: 100%;
|
|
109
|
+
height: 100%;
|
|
110
|
+
|
|
111
|
+
padding: var(--table-cell-padding-block) var(--table-cell-padding-inline);
|
|
112
|
+
line-height: var(--table-cell-line-height);
|
|
113
|
+
|
|
114
|
+
text-align: start;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* stylelint-disable selector-class-pattern */
|
|
118
|
+
:global(.text-start), :global(.text-left) {
|
|
119
|
+
.sortBtn {
|
|
120
|
+
text-align: start;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
:global(.text-end), :global(.text-right) {
|
|
124
|
+
.sortBtn {
|
|
125
|
+
text-align: end;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
:global(.text-center) {
|
|
129
|
+
.sortBtn {
|
|
130
|
+
text-align: center;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/* stylelint-enable selector-class-pattern */
|
|
134
|
+
|
|
135
|
+
.bottomArea {
|
|
136
|
+
display: flex;
|
|
137
|
+
flex-flow: row wrap;
|
|
138
|
+
gap: var(--size-md);
|
|
139
|
+
align-content: center;
|
|
140
|
+
align-items: center;
|
|
141
|
+
justify-content: flex-end;
|
|
142
|
+
margin-block-start: var(--size-xs);
|
|
143
|
+
}
|
|
144
|
+
.info {
|
|
145
|
+
font-size: var(--font-size-sm);
|
|
146
|
+
font-style: italic;
|
|
147
|
+
color: var(--text-muted);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* pagination */
|
|
151
|
+
/* .paginationNav {} */
|
|
152
|
+
.paginationList, .paginationListItem, .paginationListItemBtn {
|
|
153
|
+
padding: 0;
|
|
154
|
+
margin: 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.paginationList {
|
|
158
|
+
display: flex;
|
|
159
|
+
flex-flow: row wrap;
|
|
160
|
+
gap: 0;
|
|
161
|
+
align-items: stretch;
|
|
162
|
+
justify-content: flex-start;
|
|
163
|
+
list-style: none;
|
|
164
|
+
}
|
|
165
|
+
.paginationListItem {
|
|
166
|
+
border: var(--sdt-pagination-border);
|
|
167
|
+
border-style: solid solid solid none;
|
|
168
|
+
|
|
169
|
+
&:first-child {
|
|
170
|
+
border-inline-start-style: solid;
|
|
171
|
+
border-radius: var(--radius-xxs) 0 0 var(--radius-xxs);
|
|
172
|
+
}
|
|
173
|
+
&:last-child {
|
|
174
|
+
border-radius: 0 var(--radius-xxs) var(--radius-xxs) 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@media (hover: hover) {
|
|
178
|
+
&:hover {
|
|
179
|
+
color: var(--sdt-hover-color);
|
|
180
|
+
background-color: var(--sdt-hover-background-color);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.paginationDisabled {
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
|
|
189
|
+
.paginationListItemBtn {
|
|
190
|
+
opacity: .7;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.paginationActive {
|
|
195
|
+
color: var(--sdt-hover-color);
|
|
196
|
+
background-color: var(--sdt-hover-background-color);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.paginationListItemBtn {
|
|
200
|
+
display: flex;
|
|
201
|
+
align-items: center;
|
|
202
|
+
justify-content: center;
|
|
203
|
+
height: 100%;
|
|
204
|
+
padding: var(--sdt-pagination-padding-block) var(--sdt-pagination-padding-inline);
|
|
205
|
+
color: inherit;
|
|
206
|
+
background-color: transparent;
|
|
207
|
+
border: none;
|
|
208
|
+
|
|
209
|
+
&.hasSvg {
|
|
210
|
+
padding-inline: calc(var(--sdt-pagination-padding-inline) / 2);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
svg {
|
|
214
|
+
width: 1em;
|
|
215
|
+
aspect-ratio: 1;
|
|
216
|
+
fill: currentColor;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* purgecss end ignore */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
sdt: {
|
|
3
|
+
thead: {
|
|
4
|
+
hover: {
|
|
5
|
+
background: {
|
|
6
|
+
color: {
|
|
7
|
+
$value: 'color-mix(in srgb, {table.thead.background.color} 90%, {accent})',
|
|
8
|
+
$type: 'color'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
pagination: {
|
|
15
|
+
border: {
|
|
16
|
+
$type: 'border',
|
|
17
|
+
$value: {
|
|
18
|
+
color: '{neutral.100}',
|
|
19
|
+
width: '{btn.border.width}',
|
|
20
|
+
// style: 'solid'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
padding: {
|
|
24
|
+
block: {
|
|
25
|
+
$value: '{size.xxs}',
|
|
26
|
+
$type: 'dimension'
|
|
27
|
+
},
|
|
28
|
+
inline: {
|
|
29
|
+
$value: '{size.xs}',
|
|
30
|
+
$type: 'dimension'
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
hover: {
|
|
35
|
+
background: {
|
|
36
|
+
color: {
|
|
37
|
+
$value: '{btn.primary.background.color}',
|
|
38
|
+
$type: 'color'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
color: {
|
|
42
|
+
$value: '{btn.primary.color}',
|
|
43
|
+
$type: 'color'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// pre-elaborazione tipi dati predefiniti
|
|
4
|
+
// le chiavi che cominciano con '_' sono di questa applicazione, le altre sono di simple-datatable
|
|
5
|
+
|
|
6
|
+
import { classnames } from '../../../../index.js';
|
|
7
|
+
|
|
8
|
+
import * as styles from '../s-datatable-component.module.css';
|
|
9
|
+
|
|
10
|
+
import checkIcon from '../../../icons/check-bold.svg?inline';
|
|
11
|
+
import xIcon from '../../../icons/x-bold.svg?inline';
|
|
12
|
+
|
|
13
|
+
// col_obj è l'oggetto che descrive una singola colonna del datatable
|
|
14
|
+
// viene utilizzato per produrre l'oggetto columns di simple-datatable
|
|
15
|
+
export function parseCols(col_obj){
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if(col_obj.render == null) {
|
|
19
|
+
|
|
20
|
+
// campi template
|
|
21
|
+
if(col_obj._renderTpl) {
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...col_obj,
|
|
25
|
+
type: col_obj.type?? 'html',
|
|
26
|
+
|
|
27
|
+
// render: (value, cell /*, dataIndex, rowIndex */) => {
|
|
28
|
+
|
|
29
|
+
// cell.attributes['data-order'] = value.replace(/(<([^>]+)>)/ig,'');
|
|
30
|
+
// return value;
|
|
31
|
+
// // non viene elaborato qui perché non è possibile raggiungere la riga del json
|
|
32
|
+
// // return `<a href="${col_obj._href}">${value}</a>`;
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
} else if(col_obj._renderMode === 'id') {
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...col_obj,
|
|
41
|
+
type: 'number',
|
|
42
|
+
searchable: false,
|
|
43
|
+
cellClass: 'text-end',
|
|
44
|
+
headerClass: 'text-end',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} else if(col_obj._renderMode === 'email') {
|
|
48
|
+
return {
|
|
49
|
+
...col_obj,
|
|
50
|
+
type: 'string',
|
|
51
|
+
render: value => value.text?.replace('@', '<wbr />@<wbr />')
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// campi booleani
|
|
55
|
+
} else if (col_obj.type === 'boolean' || col_obj._renderMode === 'bool_true_only') {
|
|
56
|
+
// TODO caso in cui il valore è null nel caso si voglia differenziarlo da false
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...col_obj,
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
cellClass: styles.hasIcon,
|
|
62
|
+
headerClass: 'text-center',
|
|
63
|
+
render: (value, td) => {
|
|
64
|
+
|
|
65
|
+
if(Boolean(value)) {
|
|
66
|
+
td.attributes.class = classnames(td.attributes.class, 'text-success');
|
|
67
|
+
return checkIcon;
|
|
68
|
+
} else {
|
|
69
|
+
td.attributes.class = classnames(td.attributes.class, 'text-danger');
|
|
70
|
+
return col_obj._renderMode === 'bool_true_only'? '' : xIcon;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// campi date e datetime, symfony e no
|
|
76
|
+
// nel caso di datetime/date symfony, il valore è stato già preelaborato da _load
|
|
77
|
+
} else if(['sf_datetime', 'sf_date', 'date', 'datetime'].includes(col_obj._renderMode)) {
|
|
78
|
+
|
|
79
|
+
const _isDatetime = ['sf_datetime', 'datetime'].includes(col_obj._renderMode);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
...col_obj,
|
|
83
|
+
type: 'string',
|
|
84
|
+
cellClass: 'text-end',
|
|
85
|
+
headerClass: 'text-end',
|
|
86
|
+
|
|
87
|
+
render: (value, cell /*, dataIndex, rowIndex */) => { // value si riferisce al valore già trasformato nella pre-elaborazione dei dati
|
|
88
|
+
/* {
|
|
89
|
+
"date": "2026-03-31 07:54:31.000000",
|
|
90
|
+
"timezone_type": 3,
|
|
91
|
+
"timezone": "UTC"
|
|
92
|
+
} */
|
|
93
|
+
|
|
94
|
+
if(value == null) {
|
|
95
|
+
cell.attributes['data-order'] = ' ';
|
|
96
|
+
return '\u2014';
|
|
97
|
+
|
|
98
|
+
} else {
|
|
99
|
+
|
|
100
|
+
const dateObj = new Date(value);
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
cell.attributes['data-order'] = _isDatetime? value : value.substring(0,10);
|
|
104
|
+
|
|
105
|
+
return `<span class="text-nowrap">${dateObj.toLocaleString('it-IT', {
|
|
106
|
+
year: '2-digit',
|
|
107
|
+
month: 'short',
|
|
108
|
+
day: 'numeric',
|
|
109
|
+
})}</span>` +
|
|
110
|
+
(_isDatetime
|
|
111
|
+
? `\u2009<span class="text-xs">${dateObj.toLocaleString('it-IT', {
|
|
112
|
+
hour12: false,
|
|
113
|
+
hour:'2-digit',
|
|
114
|
+
minute:'2-digit'
|
|
115
|
+
})}</span>`
|
|
116
|
+
: '');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
} else if(col_obj._renderMode === 'numeric') {
|
|
123
|
+
return {
|
|
124
|
+
...col_obj,
|
|
125
|
+
// le classi definite dall'utente vengono unite, non sostituite
|
|
126
|
+
cellClass: classnames('text-end text-numeric', col_obj.cellClass),
|
|
127
|
+
headerClass: classnames('text-end text-numeric', col_obj.headerClass), // NB: usata anche per il footer
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
} else if(col_obj._renderMode === 'euro_no_dec') {
|
|
131
|
+
return {
|
|
132
|
+
...col_obj,
|
|
133
|
+
render: (value, cell) => {
|
|
134
|
+
// console.log(value);
|
|
135
|
+
if(value == null || isNaN(value)) {
|
|
136
|
+
cell.attributes['data-order'] = '';
|
|
137
|
+
return '\u2014';
|
|
138
|
+
|
|
139
|
+
} else {
|
|
140
|
+
cell.attributes['data-order'] = value;
|
|
141
|
+
return Number(value).toLocaleString('it-IT', {
|
|
142
|
+
minimumFractionDigits: 0,
|
|
143
|
+
maximumFractionDigits: 0,
|
|
144
|
+
useGrouping: 'always',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
// le classi definite dall'utente vengono unite, non sostituite
|
|
149
|
+
cellClass: classnames('text-nowrap text-end text-numeric', col_obj.cellClass),
|
|
150
|
+
headerClass: classnames('text-nowrap text-end text-numeric', col_obj.headerClass), // NB: usata anche per il footer
|
|
151
|
+
type: 'number'
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
} // end if not render
|
|
156
|
+
|
|
157
|
+
return col_obj;
|
|
158
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// Generazione della `searchMethod` di colonna usata da `_searchValue`.
|
|
4
|
+
//
|
|
5
|
+
// simple-datatables NON passa alla searchMethod il nodo DOM della cella, ma
|
|
6
|
+
// l'oggetto dati interno `cellType` ({ data, text?, order?, attributes? }):
|
|
7
|
+
// vedi `multiSearch` in `src/datatable.ts` (`customSearchMethod(queryColumnWord,
|
|
8
|
+
// searchRow[index], row, index, source)`). Gli `attributes` sono conservati
|
|
9
|
+
// nell'oggetto dati (`readDataCell` in `src/read_data.ts` ammette le chiavi
|
|
10
|
+
// "text", "order", "data", "attributes"), quindi `data-search` va letto da
|
|
11
|
+
// `cell.attributes['data-search']`, non con `cell.getAttribute()`.
|
|
12
|
+
|
|
13
|
+
// Punteggiatura rimossa quando `ignorePunctuation` è attivo
|
|
14
|
+
const PUNCTUATION_RX = /[.,/#!$%^&*;:{}=\-_`~()]/g;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Normalizza una stringa replicando il trattamento che simple-datatables
|
|
18
|
+
* applica ai termini di ricerca quando è attiva una `searchMethod` personalizzata.
|
|
19
|
+
*
|
|
20
|
+
* La libreria normalizza solo i termini digitati (non il contenuto della cella),
|
|
21
|
+
* con i default `sensitivity: 'base'` e `ignorePunctuation: true`: se l'haystack
|
|
22
|
+
* non riceve lo stesso trattamento, "citta" non troverebbe "Città" e "spa" non
|
|
23
|
+
* troverebbe "S.p.A.".
|
|
24
|
+
*
|
|
25
|
+
* @param {*} str Valore da normalizzare (convertito con String()).
|
|
26
|
+
* @param {object} [opts] (default: {})
|
|
27
|
+
* @param {'base'|'accent'|'case'|'variant'} [opts.sensitivity='base']
|
|
28
|
+
* 'base' → ignora maiuscole/minuscole e diacritici
|
|
29
|
+
* 'accent' → ignora maiuscole/minuscole, mantiene i diacritici
|
|
30
|
+
* 'case' → distingue maiuscole/minuscole, ignora i diacritici
|
|
31
|
+
* 'variant' → distingue tutto (default: 'base')
|
|
32
|
+
* @param {boolean} [opts.ignorePunctuation=true] (default: true)
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeSearchString(str, opts = {}) {
|
|
36
|
+
const sensitivity = opts.sensitivity ?? 'base';
|
|
37
|
+
const ignorePunctuation = opts.ignorePunctuation ?? true;
|
|
38
|
+
|
|
39
|
+
// String() anche su numeri/booleani: `_searchValue` come funzione può
|
|
40
|
+
// restituire un id numerico o un flag
|
|
41
|
+
let out = String(str ?? '');
|
|
42
|
+
|
|
43
|
+
if (sensitivity === 'base' || sensitivity === 'accent') {
|
|
44
|
+
out = out.toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
if (sensitivity === 'base' || sensitivity === 'case') {
|
|
47
|
+
out = out.normalize('NFD').replace(/\p{Diacritic}/gu, '');
|
|
48
|
+
}
|
|
49
|
+
if (ignorePunctuation) {
|
|
50
|
+
out = out.replace(PUNCTUATION_RX, '');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Restituisce la `searchMethod` di colonna per le colonne con `_searchValue`.
|
|
58
|
+
*
|
|
59
|
+
* API simple-datatables: (terms, cell, row, colIdx, source) => boolean
|
|
60
|
+
* - `terms` array di stringhe (una per parola cercata), già normalizzate dalla libreria
|
|
61
|
+
* - `cell` oggetto dati `cellType` ({ data, text?, order?, attributes? })
|
|
62
|
+
*
|
|
63
|
+
* Comportamento AND: tutti i termini devono essere presenti
|
|
64
|
+
* (come nella demo https://fiduswriter.github.io/simple-datatables/demos/22-and-search/).
|
|
65
|
+
*
|
|
66
|
+
* @param {object} [colSettings] Definizione della colonna (per `sensitivity` / `ignorePunctuation`). (default: {})
|
|
67
|
+
* @returns {(terms: string[], cell: object) => boolean}
|
|
68
|
+
*/
|
|
69
|
+
export function makeSearchMethod(colSettings = {}) {
|
|
70
|
+
const opts = {
|
|
71
|
+
sensitivity: colSettings.sensitivity,
|
|
72
|
+
ignorePunctuation: colSettings.ignorePunctuation,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (terms, cell) => {
|
|
76
|
+
const raw = cell?.attributes?.['data-search']
|
|
77
|
+
?? cell?.text
|
|
78
|
+
?? (typeof cell?.data === 'string' || typeof cell?.data === 'number' ? cell.data : '');
|
|
79
|
+
|
|
80
|
+
const haystack = normalizeSearchString(raw, opts);
|
|
81
|
+
|
|
82
|
+
return terms.every(term => haystack.includes(normalizeSearchString(term, opts)));
|
|
83
|
+
};
|
|
84
|
+
}
|