In DxDataGrid you don´t need track columns, you can track whole grid. There is a posibility of StateStoring. This is storing column visibility, if there is any grouping, sorting, columns width, value from search panel etc. You can than store it on browser local storage, if you use default save and load, or you can override it via customSave and customLoad and then is possible to use own service and store it for example in database.
Where HTML looks like:
<dx-data-grid [dataSource]="friends" [allowColumnReordering]="true"
showRowLines="true" height="100%" [allowColumnResizing]="true"
[hoverStateEnabled]="false" [width]="'100%'"
[(selectedRowKeys)]="selectedRowKeys">
<dxo-column-chooser [enabled]="true"></dxo-column-chooser>
<dxo-state-storing [enabled]="true" type="custom" [customSave]="saveGridState"
[customLoad]="loadGridState">
</dxo-state-storing>
<dxi-column dataField="Id" dataType="number" [visible]="true">
</dxi-column>
<dxi-column dataField="FirstName" dataType="string" [visible]="true">
</dxi-column>
<dxi-column dataField="LastName" dataType="string" [visible]="true">
</dxi-column>
<dxi-column dataField="Age" dataType="number" [visible]="false">
</dxi-column>
</dx-data-grid>
And ts like:
export class FriendsGridsComponent
friends: any[] = [];
stateKey = 'friendsGrid';
constructor(pageConfigService: PageConfigService){}
saveGridState(state) {
console.log('saving grid state');
this.pageConfigService.saveState(this.stateKey, state);
}
async loadGridState(): Promise<Object> {
return this.pageConfigService.restoreState(this.stateKey);
}
}
Implementation of PageConfigService is on you. In my project is big, so I don´t want to add it here whole and it is also very specific for my project. Save state is very easy, just save it somewhere. Little complicated is restoring, because you need wait until state is loaded back. If you don´t wait, it will win default settings from HTML and not your saved state.