ywana-core8 0.0.780 → 0.0.782
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/dist/index.cjs +36 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +36 -13
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +36 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/table.js +24 -7
- package/src/html/table.test.js +11 -11
package/package.json
CHANGED
package/src/html/table.js
CHANGED
@@ -38,6 +38,12 @@ export const DataTable = (props) => {
|
|
38
38
|
const keySort = (a, b, direction) => {
|
39
39
|
direction = direction !== null ? direction : 1;
|
40
40
|
|
41
|
+
// check if a and b are numbers and compare as numbers
|
42
|
+
if (!isNaN(a) && !isNaN(b)) {
|
43
|
+
a = Number(a);
|
44
|
+
b = Number(b);
|
45
|
+
}
|
46
|
+
|
41
47
|
if (a === b) { // If the values are the same, do not switch positions.
|
42
48
|
return 0;
|
43
49
|
}
|
@@ -168,7 +174,7 @@ const DataTableRow = (props) => {
|
|
168
174
|
const DataTableCell = ({ index, row, column, cell, editable }) => {
|
169
175
|
|
170
176
|
const render = (type) => {
|
171
|
-
const { id, disabled = false, min, max, onChange, format, options, item, action } = column
|
177
|
+
const { id, disabled = false, min, max, onChange, format, options, item, action, maxDecimals } = column
|
172
178
|
|
173
179
|
|
174
180
|
if (id === "checked") {
|
@@ -192,7 +198,7 @@ const DataTableCell = ({ index, row, column, cell, editable }) => {
|
|
192
198
|
case "ICON": return <Icon icon={cell} />
|
193
199
|
case "Boolean": return <BooleanCellViewer id={id} value={cell} />
|
194
200
|
case "String": return <StringCellViewer id={id} value={cell} format={format} options={options} action={action} />
|
195
|
-
case "Number": return <NumberCellViewer id={id} value={cell} format={format} />
|
201
|
+
case "Number": return <NumberCellViewer id={id} value={cell} format={format} maxDecimals={maxDecimals} />
|
196
202
|
default: return cell
|
197
203
|
}
|
198
204
|
}
|
@@ -254,7 +260,7 @@ const BooleanCellViewer = ({ id, value = false }) => {
|
|
254
260
|
* NumberCellViewer
|
255
261
|
*/
|
256
262
|
const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
|
257
|
-
|
263
|
+
/*
|
258
264
|
function formatNumber(number) {
|
259
265
|
// convert number to numeric
|
260
266
|
if (number === null) return "null"
|
@@ -267,6 +273,20 @@ const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
|
|
267
273
|
const thousands = /\B(?=(\d{3})+(?!\d))/g;
|
268
274
|
return numberPart.replace(thousands, ".") + (decimalPart ? "," + decimalPart : "");
|
269
275
|
}
|
276
|
+
*/
|
277
|
+
function formatNumber(number, maxDecimals = 0) {
|
278
|
+
if (number === null) return "null"
|
279
|
+
let result = number.toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
280
|
+
// thousands separator is a dot
|
281
|
+
var parts = result.toString().split(",");
|
282
|
+
const numberPart = parts[0];
|
283
|
+
const decimalPart = parts[1];
|
284
|
+
const thousands = /\B(?=(\d{3})+(?!\d))/g;
|
285
|
+
|
286
|
+
// limit decimal part to maxdecimals
|
287
|
+
const decimal = decimalPart ? decimalPart.substring(0, maxDecimals) : null;
|
288
|
+
return numberPart.replace(thousands, ".") + (decimal ? "," + decimal : "");
|
289
|
+
}
|
270
290
|
|
271
291
|
if (format) {
|
272
292
|
switch (format) {
|
@@ -282,11 +302,8 @@ const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
|
|
282
302
|
// if value is not a number, return value
|
283
303
|
if (isNaN(number)) return value
|
284
304
|
|
285
|
-
// if maxDecimals is defined, round number
|
286
|
-
if (maxDecimals) number = number.toFixed(maxDecimals)
|
287
|
-
|
288
305
|
// format number
|
289
|
-
return <span>{formatNumber(number)}</span>
|
306
|
+
return <span>{formatNumber(number, maxDecimals)}</span>
|
290
307
|
|
291
308
|
default:
|
292
309
|
return <span>{value}</span>
|
package/src/html/table.test.js
CHANGED
@@ -6,15 +6,15 @@ export const TableTest = (prop) => {
|
|
6
6
|
|
7
7
|
const [rows, setRows] = useState(
|
8
8
|
[
|
9
|
-
{ id: 1, checked: false, name: "John Smith" , description: "lorem ipsum 9", thumb: "https://w7.pngwing.com/pngs/881/826/png-transparent-pikachu-ash-ketchum-pokemon-vrste-pikachu-leaf-flower-meme-thumbnail.png" },
|
10
|
-
{ id: 2, checked: false, name: "Ann Martin" , description: "lorem ipsum 2", color: "#CCFFFF" },
|
11
|
-
{ id: 3, checked: false, name: "Ann Martin" , description: "lorem ipsum 8", color: "#CCFFFF" },
|
12
|
-
{ id: 4, checked: false, name: "Zack McCracken", description: "lorem ipsum 4", color: "#CCFFFF" },
|
13
|
-
{ id: 5, checked: false, name: "Ann Martin" , description: "lorem ipsum 1", color: "#CCFFFF" },
|
14
|
-
{ id: 6, checked: false, name: "John Smith" , description: "lorem ipsum 2", color: "#CCFFFF" },
|
15
|
-
{ id: 7, checked: false, name: "Ann Martin" , description: "lorem ipsum 1", color: "#CCFFFF" },
|
16
|
-
{ id: 8, checked: false, name: "Martin Freeman", description: "lorem ipsum 4", color: "#CCFFFF" , num: 890.1234567890 },
|
17
|
-
{ id: 9, checked: false, name: "Ann Martin" , description: "lorem ipsum 5", color: "#CCFFFF", date: new Date().toString() },
|
9
|
+
{ id: 1, checked: false, name: "John Smith" , description: "lorem ipsum 9", color: "#CACAFF", num: "25", thumb: "https://w7.pngwing.com/pngs/881/826/png-transparent-pikachu-ash-ketchum-pokemon-vrste-pikachu-leaf-flower-meme-thumbnail.png" },
|
10
|
+
{ id: 2, checked: false, name: "Ann Martin" , description: "lorem ipsum 2", color: "#CCFFFF", num: "1234567890.1234567890" },
|
11
|
+
{ id: 3, checked: false, name: "Ann Martin" , description: "lorem ipsum 8", color: "#CCFFFF", num: "12340.1234567890" },
|
12
|
+
{ id: 4, checked: false, name: "Zack McCracken", description: "lorem ipsum 4", color: "#CCFFFF", num: "567890.1234567890" },
|
13
|
+
{ id: 5, checked: false, name: "Ann Martin" , description: "lorem ipsum 1", color: "#CCFFFF", num: "23670.190" },
|
14
|
+
{ id: 6, checked: false, name: "John Smith" , description: "lorem ipsum 2", color: "#CCFFFF", num: "71230.10" },
|
15
|
+
{ id: 7, checked: false, name: "Ann Martin" , description: "lorem ipsum 1", color: "#CCFFFF", num: "3490.23" },
|
16
|
+
{ id: 8, checked: false, name: "Martin Freeman", description: "lorem ipsum 4", color: "#CCFFFF" , num: "890.1234567890" },
|
17
|
+
{ id: 9, checked: false, name: "Ann Martin" , description: "lorem ipsum 5", color: "#CCFFFF", num: "365", date: new Date().toString() },
|
18
18
|
]
|
19
19
|
)
|
20
20
|
|
@@ -47,7 +47,7 @@ export const TableTest = (prop) => {
|
|
47
47
|
{ id: "description", label: "Description", type: "String", sortable: true },
|
48
48
|
{ id: "color" , label: "Color" , type: "String", format: FORMATS.COLOR },
|
49
49
|
{ id: "date" , label: "Date" , type: "String", format: FORMATS.DATE },
|
50
|
-
{ id: "num" , label: "Num" , type: "Number", maxDecimals: 2 },
|
50
|
+
{ id: "num" , label: "Num" , type: "Number", maxDecimals: 2, sortable: true},
|
51
51
|
],
|
52
52
|
rows
|
53
53
|
}
|
@@ -55,7 +55,7 @@ export const TableTest = (prop) => {
|
|
55
55
|
return (
|
56
56
|
<>
|
57
57
|
<div style={{ maxHeight: "20rem", overflow: "auto", margin: "2rem", display: "flex" }}>
|
58
|
-
|
58
|
+
z<DataTable {...table1} onRowSelection={select} outlined multisort={true}/>
|
59
59
|
</div>
|
60
60
|
<div style={{ maxHeight: "20rem", overflow: "auto", margin: "2rem" }}>
|
61
61
|
<DataTable {...table1} onRowSelection={select} onCheckAll={checkAll} />
|