@@ -13,13 +13,29 @@ import listenOnRootMixin from '../../mixins/listen-on-root'
13
13
// Import styles
14
14
import './table.css'
15
15
16
- // Object of item keys that should be ignored for headers and stringification
16
+ // Object of item keys that should be ignored for headers and stringification and filter events
17
17
const IGNORED_FIELD_KEYS = {
18
18
_rowVariant : true ,
19
19
_cellVariants : true ,
20
20
_showDetails : true
21
21
}
22
22
23
+ // Return a copy of a row after all reserved fields have been filtered out
24
+ function sanitizeRow ( row ) {
25
+ return keys ( row ) . reduce ( ( obj , key ) => {
26
+ // Ignore special fields that start with _
27
+ if ( ! IGNORED_FIELD_KEYS [ key ] ) {
28
+ obj [ k ] = row [ k ]
29
+ }
30
+ return obj
31
+ } , { } )
32
+ }
33
+
34
+ // Return a new array of records/rows that have been sanitized
35
+ function sanitizeRows ( rows ) {
36
+ return rows . map ( row => sanitizeRow ( row ) )
37
+ }
38
+
23
39
// Stringifies the values of an object
24
40
// { b: 3, c: { z: 'zzz', d: null, e: 2 }, d: [10, 12, 11], a: 'one' }
25
41
// becomes
@@ -39,19 +55,11 @@ function toString (v) {
39
55
}
40
56
41
57
// Stringifies the values of a record, ignoring any special top level keys
42
- function recToString ( obj ) {
58
+ function recToString ( row ) {
43
59
if ( ! ( obj instanceof Object ) ) {
44
60
return ''
45
61
}
46
- return toString (
47
- keys ( obj ) . reduce ( ( o , k ) => {
48
- // Ignore special fields that start with _
49
- if ( ! IGNORED_FIELD_KEYS [ k ] ) {
50
- o [ k ] = obj [ k ]
51
- }
52
- return o
53
- } , { } )
54
- )
62
+ return toString ( sanitizeRow ( row ) )
55
63
}
56
64
57
65
function defaultSortCompare ( a , b , sortBy ) {
@@ -413,8 +421,8 @@ export default {
413
421
localSortBy : this . sortBy || '' ,
414
422
localSortDesc : this . sortDesc || false ,
415
423
localItems : [ ] ,
416
- // Note: filteredItems only used to determine if # of items changed
417
- filteredItems : [ ] ,
424
+ // Note: filteredItems only used to determine if items changed (set to null initially)
425
+ filteredItems : null ,
418
426
localBusy : false
419
427
}
420
428
} ,
@@ -617,10 +625,23 @@ export default {
617
625
this . $emit ( 'context-changed' , newVal )
618
626
}
619
627
} ,
620
- filteredItems ( newVal , oldVal ) {
621
- if ( this . localFiltering && newVal . length !== oldVal . length ) {
622
- // Emit a filtered notification event, as number of filtered items has changed
623
- this . $emit ( 'filtered' , newVal )
628
+ filteredItems ( newRows , oldRows ) {
629
+ if ( ! this . localFiltering || newRows === oldRows ) {
630
+ // If not local Filtering or nothing changed, don't emit a filtered event
631
+ return
632
+ }
633
+ if ( oldRows === null || newRows === null ) {
634
+ // If first run of updating items, don't emit a filtered event.
635
+ return
636
+ }
637
+ // We compare lengths first for performance reasons, even though looseEqual
638
+ // does this test, as we must sanitize the row data before passing it to
639
+ // looseEqual, of which both could take time to run on long record sets!
640
+ if ( newRows . length !== oldRows . length ||
641
+ ! looseEqual ( sanitizeRows ( newRows ) , sanitizeRows ( oldRows ) ) ) {
642
+ // Emit a filtered notification event, as filtered items has changed
643
+ // Note this may fire before the v-model has updated
644
+ this . $emit ( 'filtered' , newRows )
624
645
}
625
646
} ,
626
647
sortDesc ( newVal , oldVal ) {
0 commit comments