spark-grid-vue3 0.0.2 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spark-grid-vue3",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "",
@@ -65,6 +65,7 @@ export type Action = {
65
65
  }
66
66
 
67
67
  export type ComputedColumn = () => Column[]
68
+ export type UniqueKeyIdentifier = (row: Row) => string
68
69
 
69
70
  export type SparkGridConfig = {
70
71
  url?: string | function,
@@ -111,6 +112,7 @@ export type SparkGridConfig = {
111
112
  onClickCell?: OnCellEvent,
112
113
  onDoubleClickCell?: OnCellEvent,
113
114
  onContextMenu?: OnContextMenu,
115
+ uniqueKeyIdentifier?: string | UniqueKeyIdentifier,
114
116
  }
115
117
 
116
118
  export type Row = {
@@ -3,15 +3,28 @@ import type {GridComponent, Row} from "../definition/types"
3
3
  export class RadioButtonSelectedMapper {
4
4
  static map(row: Row, grid: GridComponent) {
5
5
  if (grid._selectedRadioRow) {
6
- const uuidMatches = row._uuid == grid._selectedRadioRow._uuid
7
- const idMatches = row.id == grid._selectedRadioRow.id
6
+ const uuidMatches: boolean = row._uuid == grid._selectedRadioRow._uuid
8
7
 
9
- if (uuidMatches || idMatches) {
8
+ if (uuidMatches || this._idMatches(row, grid)) {
10
9
  row._isRadioChecked = true;
11
10
  }
12
-
13
11
  }
14
12
 
15
13
  return row;
16
14
  }
15
+
16
+ static _idMatches(row: Row, grid: GridComponent): boolean {
17
+ if (!grid._selectedRadioRow) {
18
+ return false
19
+ }
20
+
21
+ if (typeof grid.config.uniqueKeyIdentifier == 'string') {
22
+ const uniqueKey = grid.config.uniqueKeyIdentifier
23
+ return row[uniqueKey] == grid._selectedRadioRow[uniqueKey]
24
+ } else if (typeof grid.config.uniqueKeyIdentifier == 'function') {
25
+ return grid.config.uniqueKeyIdentifier(row) == grid.config.uniqueKeyIdentifier(grid._selectedRadioRow)
26
+ }
27
+
28
+ return row.id == grid._selectedRadioRow.id
29
+ }
17
30
  }