@@ -47,6 +47,7 @@ export class TableStore {
4747 public entriesLoader : ( guids : TableGuids , setStore : boolean , clean : boolean ) => void ;
4848
4949 @observable public isLoading : boolean ;
50+ @observable public waitingForAxis : boolean ;
5051 @observable public contextObject : mendix . lib . MxObject | null ;
5152 @observable public columns : ColumnObject [ ] = [ ] ;
5253 @observable public rows : RowObject [ ] = [ ] ;
@@ -59,6 +60,7 @@ export class TableStore {
5960
6061 private reloadOnColChange = true ;
6162 private reloadOnRowChange = true ;
63+ private hasEntriesLoader = false ;
6264 private sortingTypeRows : SortingType ;
6365 private sortingTypeColumns : SortingType ;
6466
@@ -77,6 +79,7 @@ export class TableStore {
7779 } = opts ;
7880
7981 this . isLoading = false ;
82+ this . waitingForAxis = false ;
8083 this . contextObject = contextObject || null ;
8184 this . subscriptionHandler = subscriptionHandler || ( ( ) : void => { } ) ;
8285 this . onSelectionChangeHandler = onSelectionChange || ( ( ) : void => { } ) ;
@@ -85,12 +88,29 @@ export class TableStore {
8588 this . executeOnSelectionChange = this . executeOnSelectionChange . bind ( this ) ;
8689
8790 this . entriesLoader = entriesLoader || ( ( _guids : TableGuids ) : void => { } ) ;
91+ this . hasEntriesLoader = typeof entriesLoader !== "undefined" ;
8892 this . validationMessages = validationMessages || [ ] ;
8993
9094 this . sortingTypeRows = sortingTypeRows || "none" ;
9195 this . sortingTypeColumns = sortingTypeColumns || "none" ;
96+ }
9297
93- if ( entriesLoader ) {
98+ // Other actions
99+ @action
100+ public setContext ( obj ?: mendix . lib . MxObject ) : void {
101+ this . contextObject = obj || null ;
102+ this . resetTable ( ) ;
103+ }
104+
105+ @action resetTable ( ) : void {
106+ this . columns . forEach ( col => col . clearSubscriptions ( ) ) ;
107+ this . rows . forEach ( row => row . clearSubscriptions ( ) ) ;
108+ this . entries . forEach ( entry => entry . clearSubscriptions ( ) ) ;
109+ this . columns = [ ] ;
110+ this . rows = [ ] ;
111+ this . entries = [ ] ;
112+ if ( this . hasEntriesLoader && ! this . waitingForAxis ) {
113+ this . waitingForAxis = true ;
94114 when (
95115 ( ) => {
96116 return this . hasColumns && this . hasRows ;
@@ -99,17 +119,12 @@ export class TableStore {
99119 if ( ! this . disabled ) {
100120 this . entriesLoader ( this . tableGuids , true , true ) ;
101121 }
122+ this . waitingForAxis = false ;
102123 }
103124 ) ;
104125 }
105126 }
106127
107- // Other actions
108- @action
109- public setContext ( obj ?: mendix . lib . MxObject ) : void {
110- this . contextObject = obj || null ;
111- }
112-
113128 @action
114129 setLoading ( state : boolean ) : void {
115130 this . isLoading = state ;
0 commit comments