ywana-core8 0.0.779 → 0.0.781

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.779",
3
+ "version": "0.0.781",
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
@@ -13,14 +13,19 @@ const isFunction = value => value && (Object.prototype.toString.call(value) ===
13
13
  */
14
14
  export const DataTable = (props) => {
15
15
 
16
- const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className, emptyMessage = "No Results Found" } = props
16
+ const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className, emptyMessage = "No Results Found", multisort = false } = props
17
17
  const [sortDir, setSortDir] = useState({})
18
18
  const [allChecked, setAllChecked] = useState(false)
19
19
 
20
20
  function changeSort(id) {
21
- const nextDir = sortDir[id] ? sortDir[id] * -1 : 1
22
- const next = Object.assign({}, sortDir, { [id]: nextDir })
23
- setSortDir(next)
21
+ if (multisort) {
22
+ const nextDir = sortDir[id] ? sortDir[id] * -1 : 1
23
+ const next = Object.assign({}, sortDir, { [id]: nextDir })
24
+ setSortDir(next)
25
+ } else {
26
+ const nextDir = sortDir[id] ? sortDir[id] * -1 : 1
27
+ setSortDir({ [id]: nextDir })
28
+ }
24
29
  }
25
30
 
26
31
  function multiSort(array, sortObject = {}) {
@@ -33,6 +38,12 @@ export const DataTable = (props) => {
33
38
  const keySort = (a, b, direction) => {
34
39
  direction = direction !== null ? direction : 1;
35
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
+
36
47
  if (a === b) { // If the values are the same, do not switch positions.
37
48
  return 0;
38
49
  }
@@ -270,10 +281,10 @@ const NumberCellViewer = ({ id, value, format, maxDecimals }) => {
270
281
  case FORMATS.PERCENT:
271
282
  return <span>{value.toLocaleString('es-ES', { style: 'percent', minimumFractionDigits: 2 })}</span>
272
283
  case "ES_es":
273
-
284
+
274
285
  // convert value to number
275
286
  let number = Number(value)
276
-
287
+
277
288
  // if value is not a number, return value
278
289
  if (isNaN(number)) return value
279
290
 
@@ -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 ", 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 ", color: "#CCFFFF" },
11
- { id: 3, checked: false, name: "Ann Martin" , description: "lorem ipsum ", color: "#CCFFFF" },
12
- { id: 4, checked: false, name: "Zack McCracken", description: "lorem ipsum ", color: "#CCFFFF" },
13
- { id: 5, checked: false, name: "Ann Martin" , description: "lorem ipsum ", color: "#CCFFFF" },
14
- { id: 6, checked: false, name: "John Smith" , description: "lorem ipsum ", color: "#CCFFFF" },
15
- { id: 7, checked: false, name: "Ann Martin" , description: "lorem ipsum ", color: "#CCFFFF" },
16
- { id: 8, checked: false, name: "Martin Freeman", description: "lorem ipsum ", color: "#CCFFFF" , num: 890.1234567890 },
17
- { id: 9, checked: false, name: "Ann Martin" , description: "lorem ipsum ", 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", date: new Date().toString() },
18
18
  ]
19
19
  )
20
20
 
@@ -44,10 +44,10 @@ export const TableTest = (prop) => {
44
44
  { id: "index" , label: "#" , type: "INDEX" },
45
45
  { id: "checked" , onChange: check },
46
46
  { id: "name" , label: "Name" , type: "String", sortable: true, filtrable: true },
47
- { id: "description", label: "Description", type: "String" },
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
- <DataTable {...table1} onRowSelection={select} outlined />
58
+ x<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} />