Skip to content

Commit beb3a2d

Browse files
committed
selection.grid.CellRowModel: switch to store record ids instead of row DOM ids #6673
1 parent 3dc1999 commit beb3a2d

3 files changed

Lines changed: 46 additions & 43 deletions

File tree

src/selection/grid/BaseModel.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ class BaseModel extends Model {
8080
/**
8181
* Get the record for a given event path
8282
* @param {Object[]} path
83-
* @param {String} nodeId
8483
* @returns {Number|String|null}
8584
*/
86-
getRecord(path, nodeId) {
85+
getRecord(path) {
8786
let node, rowIndex;
8887

8988
for (node of path) {
90-
if (node.id === nodeId) {
89+
if (node.aria.rowindex) {
9190
rowIndex = parseInt(node.aria.rowindex);
9291

9392
// aria-rowindex is 1 based & also includes the header
@@ -100,6 +99,14 @@ class BaseModel extends Model {
10099
return null
101100
}
102101

102+
/**
103+
* @param {Record} record
104+
* @returns {Boolean}
105+
*/
106+
hasAnnotations(record) {
107+
return !!Object.getOwnPropertyDescriptor(record.__proto__, this.view.selectedRecordField)
108+
}
109+
103110
/**
104111
* Checks if an event path contains a grid cell editor
105112
* @param {Object} data
@@ -157,6 +164,20 @@ class BaseModel extends Model {
157164
toggleRowSelection(recordId, silent=false) {
158165
this[this.isSelectedRow(recordId) ? 'deselectRow' : 'selectRow'](recordId, silent)
159166
}
167+
168+
/**
169+
*
170+
*/
171+
unregister() {
172+
let me = this,
173+
countRows = me.selectedRows.length;
174+
175+
me.selectedRows = [];
176+
177+
countRows > 0 && me.view.createViewData();
178+
179+
super.unregister()
180+
}
160181
}
161182

162183
export default Neo.setupClass(BaseModel);

src/selection/grid/CellRowModel.mjs

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ class CellRowModel extends CellModel {
2020
* @member {String} cls='neo-selection-cellrowmodel'
2121
* @protected
2222
*/
23-
cls: 'neo-selection-cellrowmodel',
24-
/**
25-
* Storing the node ids
26-
* @member {String[]} selectedRows=[]
27-
* @protected
28-
*/
29-
selectedRows: []
23+
cls: 'neo-selection-cellrowmodel'
3024
}
3125

3226
/**
@@ -35,12 +29,14 @@ class CellRowModel extends CellModel {
3529
onCellClick(data) {
3630
let me = this,
3731
{view} = me,
38-
record = view.getRecord(data.data.currentTarget),
39-
rowId = view.getRowId(record);
32+
record = me.getRecord(data.data.path);
4033

41-
if (rowId) {
42-
me.selectedRows = [rowId];
43-
view.createViewData(true)
34+
if (record) {
35+
if (me.hasAnnotations(record)) {
36+
me.updateAnnotations(record)
37+
} else {
38+
me.toggleRowSelection(record[view.store.getKeyProperty()], true) // silent
39+
}
4440
}
4541

4642
super.onCellClick(data)
@@ -54,35 +50,30 @@ class CellRowModel extends CellModel {
5450
{view} = me,
5551
{store} = view,
5652
countRecords = store.getCount(),
57-
rowId = me.selectedRows[0] || view.getRowId(store.getAt(0)),
58-
record = view.getRecord(rowId),
53+
keyProperty = store.getKeyProperty(),
54+
recordId = me.selectedRows[0] || store.getAt(0)[keyProperty],
55+
record = store.get(recordId),
5956
index = store.indexOf(record),
60-
newIndex = (index + step) % countRecords,
61-
id;
57+
newIndex = (index + step) % countRecords;
6258

6359
while (newIndex < 0) {
6460
newIndex += countRecords
6561
}
6662

67-
id = view.getRowId(store.getAt(newIndex));
63+
record = store.getAt(newIndex);
6864

69-
if (id) {
70-
me.selectedRows = [id];
71-
view.createViewData(true)
65+
if (me.hasAnnotations(record)) {
66+
me.updateAnnotations(record)
67+
} else {
68+
recordId = record[keyProperty];
69+
70+
if (recordId) {
71+
me.selectRow(recordId, true) // silent
72+
}
7273
}
7374

7475
super.onNavKeyRow(step)
7576
}
76-
77-
/**
78-
*
79-
*/
80-
unregister() {
81-
this.selectedRows = [];
82-
this.view.createViewData();
83-
84-
super.unregister()
85-
}
8677
}
8778

8879
export default Neo.setupClass(CellRowModel);

src/selection/grid/RowModel.mjs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ class RowModel extends BaseModel {
4343
super.destroy(...args)
4444
}
4545

46-
/**
47-
* @param {Record} record
48-
* @returns {Boolean}
49-
*/
50-
hasAnnotations(record) {
51-
return !!Object.getOwnPropertyDescriptor(record.__proto__, this.view.selectedRecordField)
52-
}
53-
5446
/**
5547
* @param {Object} data
5648
*/
@@ -104,9 +96,8 @@ class RowModel extends BaseModel {
10496
*/
10597
onRowClick({data}) {
10698
let me = this,
107-
id = data.currentTarget,
10899
{view} = me,
109-
record = id && me.getRecord(data.path, id),
100+
record = me.getRecord(data.path),
110101
recordId;
111102

112103
if (record) {

0 commit comments

Comments
 (0)