41
41
<template v-if =" expanded && node .children && node .children .length " >
42
42
<TreeTableRow
43
43
v-for =" childNode of node.children"
44
- :key =" childNode.key"
44
+ :key =" nodeKey(childNode)"
45
+ :dataKey =" dataKey"
45
46
:columns =" columns"
46
47
:node =" childNode"
47
48
:parentNode =" node"
@@ -76,6 +77,10 @@ export default {
76
77
type: null ,
77
78
default: null
78
79
},
80
+ dataKey: {
81
+ type: [String , Function ],
82
+ default: ' key'
83
+ },
79
84
parentNode: {
80
85
type: null ,
81
86
default: null
@@ -150,6 +155,9 @@ export default {
150
155
onTouchEnd () {
151
156
this .nodeTouched = true ;
152
157
},
158
+ nodeKey (node ) {
159
+ return ObjectUtils .resolveFieldData (node, this .dataKey );
160
+ },
153
161
onKeyDown (event , item ) {
154
162
switch (event .code ) {
155
163
case ' ArrowDown' :
@@ -320,8 +328,8 @@ export default {
320
328
});
321
329
},
322
330
propagateDown (node , check , selectionKeys ) {
323
- if (check) selectionKeys[node . key ] = { checked: true , partialChecked: false };
324
- else delete selectionKeys[node . key ];
331
+ if (check) selectionKeys[this . nodeKey (node) ] = { checked: true , partialChecked: false };
332
+ else delete selectionKeys[this . nodeKey (node) ];
325
333
326
334
if (node .children && node .children .length ) {
327
335
for (let child of node .children ) {
@@ -336,19 +344,19 @@ export default {
336
344
let childPartialSelected = false ;
337
345
338
346
for (let child of this .node .children ) {
339
- if (_selectionKeys[child . key ] && _selectionKeys[child . key ].checked ) checkedChildCount++ ;
340
- else if (_selectionKeys[child . key ] && _selectionKeys[child . key ].partialChecked ) childPartialSelected = true ;
347
+ if (_selectionKeys[this . nodeKey (child) ] && _selectionKeys[this . nodeKey (child) ].checked ) checkedChildCount++ ;
348
+ else if (_selectionKeys[this . nodeKey (child) ] && _selectionKeys[this . nodeKey (child) ].partialChecked ) childPartialSelected = true ;
341
349
}
342
350
343
351
if (check && checkedChildCount === this .node .children .length ) {
344
- _selectionKeys[this .node . key ] = { checked: true , partialChecked: false };
352
+ _selectionKeys[this .nodeKey ( this . node ) ] = { checked: true , partialChecked: false };
345
353
} else {
346
354
if (! check) {
347
- delete _selectionKeys[this .node . key ];
355
+ delete _selectionKeys[this .nodeKey ( this . node ) ];
348
356
}
349
357
350
- if (childPartialSelected || (checkedChildCount > 0 && checkedChildCount !== this .node .children .length )) _selectionKeys[this .node . key ] = { checked: false , partialChecked: true };
351
- else _selectionKeys[this .node . key ] = { checked: false , partialChecked: false };
358
+ if (childPartialSelected || (checkedChildCount > 0 && checkedChildCount !== this .node .children .length )) _selectionKeys[this .nodeKey ( this . node ) ] = { checked: false , partialChecked: true };
359
+ else _selectionKeys[this .nodeKey ( this . node ) ] = { checked: false , partialChecked: false };
352
360
}
353
361
354
362
this .$emit (' checkbox-change' , {
@@ -364,19 +372,19 @@ export default {
364
372
let childPartialSelected = false ;
365
373
366
374
for (let child of this .node .children ) {
367
- if (_selectionKeys[child . key ] && _selectionKeys[child . key ].checked ) checkedChildCount++ ;
368
- else if (_selectionKeys[child . key ] && _selectionKeys[child . key ].partialChecked ) childPartialSelected = true ;
375
+ if (_selectionKeys[this . nodeKey (child) ] && _selectionKeys[this . nodeKey (child) ].checked ) checkedChildCount++ ;
376
+ else if (_selectionKeys[this . nodeKey (child) ] && _selectionKeys[this . nodeKey (child) ].partialChecked ) childPartialSelected = true ;
369
377
}
370
378
371
379
if (check && checkedChildCount === this .node .children .length ) {
372
- _selectionKeys[this .node . key ] = { checked: true , partialChecked: false };
380
+ _selectionKeys[this .nodeKey ( this . node ) ] = { checked: true , partialChecked: false };
373
381
} else {
374
382
if (! check) {
375
- delete _selectionKeys[this .node . key ];
383
+ delete _selectionKeys[this .nodeKey ( this . node ) ];
376
384
}
377
385
378
- if (childPartialSelected || (checkedChildCount > 0 && checkedChildCount !== this .node .children .length )) _selectionKeys[this .node . key ] = { checked: false , partialChecked: true };
379
- else _selectionKeys[this .node . key ] = { checked: false , partialChecked: false };
386
+ if (childPartialSelected || (checkedChildCount > 0 && checkedChildCount !== this .node .children .length )) _selectionKeys[this .nodeKey ( this . node ) ] = { checked: false , partialChecked: true };
387
+ else _selectionKeys[this .nodeKey ( this . node ) ] = { checked: false , partialChecked: false };
380
388
}
381
389
382
390
this .$emit (' checkbox-change' , {
@@ -402,19 +410,19 @@ export default {
402
410
return [this .node .styleClass , this .cx (' row' )];
403
411
},
404
412
expanded () {
405
- return this .expandedKeys && this .expandedKeys [this .node . key ] === true ;
413
+ return this .expandedKeys && this .expandedKeys [this .nodeKey ( this . node ) ] === true ;
406
414
},
407
415
leaf () {
408
416
return this .node .leaf === false ? false : ! (this .node .children && this .node .children .length );
409
417
},
410
418
selected () {
411
- return this .selectionMode && this .selectionKeys ? this .selectionKeys [this .node . key ] === true : false ;
419
+ return this .selectionMode && this .selectionKeys ? this .selectionKeys [this .nodeKey ( this . node ) ] === true : false ;
412
420
},
413
421
checked () {
414
- return this .selectionKeys ? this .selectionKeys [this .node . key ] && this .selectionKeys [this .node . key ].checked : false ;
422
+ return this .selectionKeys ? this .selectionKeys [this .nodeKey ( this . node ) ] && this .selectionKeys [this .nodeKey ( this . node ) ].checked : false ;
415
423
},
416
424
partialChecked () {
417
- return this .selectionKeys ? this .selectionKeys [this .node . key ] && this .selectionKeys [this .node . key ].partialChecked : false ;
425
+ return this .selectionKeys ? this .selectionKeys [this .nodeKey ( this . node ) ] && this .selectionKeys [this .nodeKey ( this . node ) ].partialChecked : false ;
418
426
},
419
427
getAriaSelected () {
420
428
return this .selectionMode === ' single' || this .selectionMode === ' multiple' ? this .selected : null ;
0 commit comments