ywana-core8 0.0.781 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.781",
3
+ "version": "0.0.782",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/html/table.js CHANGED
@@ -174,7 +174,7 @@ const DataTableRow = (props) => {
174
174
  const DataTableCell = ({ index, row, column, cell, editable }) => {
175
175
 
176
176
  const render = (type) => {
177
- 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
178
178
 
179
179
 
180
180
  if (id === "checked") {
@@ -198,7 +198,7 @@ const DataTableCell = ({ index, row, column, cell, editable }) => {
198
198
  case "ICON": return <Icon icon={cell} />
199
199
  case "Boolean": return <BooleanCellViewer id={id} value={cell} />
200
200
  case "String": return <StringCellViewer id={id} value={cell} format={format} options={options} action={action} />
201
- case "Number": return <NumberCellViewer id={id} value={cell} format={format} />
201
+ case "Number": return <NumberCellViewer id={id} value={cell} format={format} maxDecimals={maxDecimals} />
202
202
  default: return cell
203
203
  }
204
204
  }
@@ -260,7 +260,7 @@ const BooleanCellViewer = ({ id, value = false }) => {
260
260
  * NumberCellViewer
261
261
  */
262
262
  const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
263
-
263
+ /*
264
264
  function formatNumber(number) {
265
265
  // convert number to numeric
266
266
  if (number === null) return "null"
@@ -273,6 +273,20 @@ const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
273
273
  const thousands = /\B(?=(\d{3})+(?!\d))/g;
274
274
  return numberPart.replace(thousands, ".") + (decimalPart ? "," + decimalPart : "");
275
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
+ }
276
290
 
277
291
  if (format) {
278
292
  switch (format) {
@@ -288,11 +302,8 @@ const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
288
302
  // if value is not a number, return value
289
303
  if (isNaN(number)) return value
290
304
 
291
- // if maxDecimals is defined, round number
292
- if (maxDecimals) number = number.toFixed(maxDecimals)
293
-
294
305
  // format number
295
- return <span>{formatNumber(number)}</span>
306
+ return <span>{formatNumber(number, maxDecimals)}</span>
296
307
 
297
308
  default:
298
309
  return <span>{value}</span>
@@ -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", 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", 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
 
@@ -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
- x<DataTable {...table1} onRowSelection={select} outlined multisort={true}/>
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} />