Skip to content

Commit af821fa

Browse files
committed
table.View: afterSetStore() #6653
1 parent c3e536a commit af821fa

File tree

3 files changed

+84
-71
lines changed

3 files changed

+84
-71
lines changed

src/grid/Container.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class GridContainer extends BaseContainer {
563563

564564
me.store.sort(opts);
565565
me.removeSortingCss(opts.property);
566-
me.view.onStoreLoad()
566+
opts.direction && me.view.onStoreLoad()
567567
}
568568

569569
/**

src/table/Container.mjs

Lines changed: 34 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,29 @@ class Container extends BaseContainer {
232232
}
233233
}
234234

235+
/**
236+
* Triggered after the store config got changed
237+
* @param {Number} value
238+
* @param {Number} oldValue
239+
* @protected
240+
*/
241+
afterSetStore(value, oldValue) {
242+
let me = this,
243+
listeners = {
244+
filter: me.onStoreFilter,
245+
load : me.onStoreLoad,
246+
scope : me
247+
};
248+
249+
value ?.on(listeners);
250+
oldValue?.un(listeners);
251+
252+
// in case we dynamically change the store, the view needs to get the new reference
253+
if (me.view) {
254+
me.view.store = value
255+
}
256+
}
257+
235258
/**
236259
* Triggered after the useCustomScrollbars config got changed
237260
* @param {Boolean} value
@@ -293,35 +316,13 @@ class Container extends BaseContainer {
293316

294317
/**
295318
* Triggered before the store config gets changed.
296-
* @param {Neo.data.Store} value
297-
* @param {Neo.data.Store} oldValue
319+
* @param {Object|Neo.data.Store|null} value
320+
* @param {Neo.data.Store} oldValue
298321
* @protected
299322
*/
300323
beforeSetStore(value, oldValue) {
301-
oldValue?.destroy();
302-
303324
if (value) {
304-
let me = this,
305-
306-
listeners = {
307-
filter : me.onStoreFilter,
308-
load : me.onStoreLoad,
309-
recordChange: me.onStoreRecordChange,
310-
scope : me
311-
};
312-
313-
if (value instanceof Store) {
314-
value.on(listeners)
315-
} else {
316-
value = ClassSystemUtil.beforeSetInstance(value, Store, {
317-
listeners
318-
})
319-
}
320-
321-
// in case we dynamically change the store, the view needs to get the new reference
322-
if (me.view) {
323-
me.view.store = value
324-
}
325+
value = ClassSystemUtil.beforeSetInstance(value, Store)
325326
}
326327

327328
return value
@@ -404,19 +405,6 @@ class Container extends BaseContainer {
404405
return columns
405406
}
406407

407-
/**
408-
*
409-
*/
410-
createViewData() {
411-
let me = this;
412-
413-
me.view.createViewData();
414-
415-
if (me.useCustomScrollbars && me.scrollbarsCssApplied === false) {
416-
me.applyCustomScrollbarsCss()
417-
}
418-
}
419-
420408
/**
421409
* @override
422410
* @returns {*}
@@ -458,50 +446,29 @@ class Container extends BaseContainer {
458446

459447
me.store.sort(opts);
460448
me.removeSortingCss(opts.property);
461-
me.onStoreLoad(me.store.items)
449+
opts.direction && me.view.onStoreLoad()
462450
}
463451

464452
/**
465453
*
466454
*/
467455
onStoreFilter() {
468-
this.onStoreLoad(this.store.items)
456+
this.onStoreLoad()
469457
}
470458

471459
/**
472-
* @param {Object[]} data
473460
* @protected
474461
*/
475-
onStoreLoad(data) {
462+
onStoreLoad() {
476463
let me = this;
477464

478-
if (me.rendered) {
479-
me.createViewData();
480-
481-
if (me.store.sorters.length < 1) {
482-
me.removeSortingCss()
483-
}
484-
} else {
485-
me.on('rendered', () => {
486-
me.timeout(50).then(() => {
487-
me.createViewData()
488-
})
489-
}, me, {once: true})
465+
if (me.useCustomScrollbars && me.scrollbarsCssApplied === false) {
466+
me.applyCustomScrollbarsCss()
490467
}
491-
}
492468

493-
/**
494-
* Gets triggered after changing the value of a record field.
495-
* E.g. myRecord.foo = 'bar';
496-
* @param {Object} opts
497-
* @param {String} opts.field The name of the field which got changed
498-
* @param {Neo.data.Model} opts.model The model instance of the changed record
499-
* @param {*} opts.oldValue
500-
* @param {Object} opts.record
501-
* @param {*} opts.value
502-
*/
503-
onStoreRecordChange(opts) {
504-
this.view.onStoreRecordChange(opts)
469+
if (me.store.sorters?.length < 1) {
470+
me.removeSortingCss()
471+
}
505472
}
506473

507474
/**

src/table/View.mjs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class View extends Component {
5656
*/
5757
selectedRecordField: 'annotations.selected',
5858
/**
59-
* @member {Neo.data.Store|null} store=null
59+
* @member {Neo.data.Store|null} store_=null
6060
*/
61-
store: null,
61+
store_: null,
6262
/**
6363
* @member {Boolean} useRowRecordIds=true
6464
*/
@@ -112,6 +112,25 @@ class View extends Component {
112112
this.rendered && value.register(this)
113113
}
114114

115+
/**
116+
* Triggered after the store config got changed
117+
* @param {Number} value
118+
* @param {Number} oldValue
119+
* @protected
120+
*/
121+
afterSetStore(value, oldValue) {
122+
let me = this,
123+
listeners = {
124+
filter : me.onStoreFilter,
125+
load : me.onStoreLoad,
126+
recordChange: me.onStoreRecordChange,
127+
scope : me
128+
};
129+
130+
oldValue?.un(listeners);
131+
value ?.on(listeners);
132+
}
133+
115134
/**
116135
* @param {Object} data
117136
* @param {String} [data.cellId]
@@ -523,6 +542,33 @@ class View extends Component {
523542
this.fireRowEvent(data, 'rowDoubleClick')
524543
}
525544

545+
/**
546+
*
547+
*/
548+
onStoreFilter() {
549+
this.onStoreLoad()
550+
}
551+
552+
/**
553+
* @param {Object[]} data
554+
* @protected
555+
*/
556+
onStoreLoad(data) {
557+
let me = this;
558+
559+
me.createViewData();
560+
561+
if (me.mounted) {
562+
me.timeout(50).then(() => {
563+
Neo.main.DomAccess.scrollTo({
564+
direction: 'top',
565+
id : me.vdom.id,
566+
value : 0
567+
})
568+
})
569+
}
570+
}
571+
526572
/**
527573
* Gets triggered after changing the value of a record field.
528574
* E.g. myRecord.foo = 'bar';
@@ -531,7 +577,7 @@ class View extends Component {
531577
* @param {Neo.data.Model} opts.model The model instance of the changed record
532578
* @param {Object} opts.record
533579
*/
534-
onStoreRecordChange({fields, model, record}) {
580+
onStoreRecordChange({fields, record}) {
535581
let me = this,
536582
fieldNames = fields.map(field => field.name),
537583
needsUpdate = false,

0 commit comments

Comments
 (0)