Skip to content

Commit 4f389a2

Browse files
Merge pull request #1551 from rocket-admin/fix-sorting
table view: fix default sorting
2 parents 420ee85 + 4d7e7db commit 4f389a2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

frontend/src/app/components/dashboard/db-table-view/db-table-view.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,16 @@ export class DbTableViewComponent implements OnInit, OnChanges {
202202
);
203203

204204
if (!loading && this.tableData.defaultSort !== undefined) {
205-
// Update defaultSort reference whenever data loads
206-
this.defaultSort = this.tableData.defaultSort;
207-
208205
console.log('DbTableViewComponent tableData loaded:', this.tableData);
209206
console.log('DbTableViewComponent tableData.defaultSort loaded:', this.tableData.defaultSort);
210207

211-
// Only initialize sort on first load (or after table switch when sortInitialized was reset)
208+
// Only initialize sort and defaultSort on first load (or after table switch when sortInitialized was reset)
212209
if (!this.sortInitialized) {
213210
this.sortInitialized = true;
214211

212+
// Only sync defaultSort from server on initial load, not on subsequent sort/pagination changes
213+
this.defaultSort = this.tableData.defaultSort;
214+
215215
// Initialize sort based on priority: URL params > default sort
216216
if (urlSortActive && urlSortDirection) {
217217
// Use sort from URL
@@ -266,6 +266,9 @@ export class DbTableViewComponent implements OnInit, OnChanges {
266266
this.sort.active = '';
267267
this.sort.direction = '' as any;
268268

269+
// Reset defaultSort so the previous table's default doesn't show on the new table
270+
this.defaultSort = null;
271+
269272
// Reset the sortInitialized flag so the sort gets re-initialized with new table's default sort
270273
this.sortInitialized = false;
271274
}

0 commit comments

Comments
 (0)