Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

table.apiEvent sortBy not working properly? #282

Closed
piscisferro opened this issue Jan 15, 2020 · 3 comments
Closed

table.apiEvent sortBy not working properly? #282

piscisferro opened this issue Jan 15, 2020 · 3 comments

Comments

@piscisferro
Copy link

piscisferro commented Jan 15, 2020

Hi!

In my project, I'm trying to make the pagination persistent between different views. For the most part, I got it working, but for some reason, the sorting is not working right, every time I set the sorting using table.apiEvent sortBy, order is always "desc", even If I hardcode it to be "asc"

Code example:

export class TableComponent implements OnInit {

 constructor(private tablePaginationService: TablePaginationService, private cdr: ChangeDetectorRef) {
    this.configuration = { ...DefaultConfig };
    this.configuration.paginationRangeEnabled = true;
    this.configuration.paginationEnabled = true;
  }
}

  ngAfterViewInit(): void {
   this.storedPagination = this.tablePaginationService.getStoredPagination();

    if (this.storedPagination) {
      this.pagination = this.storedPagination;

      if (this.pagination.sort) {
        this.table.apiEvent({
          type: API.sortBy,
          value: { column: this.pagination.sort, order: <'asc' | 'desc'>this.pagination.order },
        });
      }

      this.cdr.detectChanges();
    }
  }

What I do is get the pagination and sorting from the "OnPagination" and "OnOrder" events (just like server pagination demo), then I stored it in a provider and retrieve it when needed (in this case, in the ngAfterViewInit).

The result is that I get always a "desc" in order, I tried hardcoding asc with no results, the table just fire a "OnOrder" event with a "desc" value when setting the sortBy using the table.apiEvent. I don't know if I'm doing something wrong or the Table is not working properly :/

thanks in advance!

@piscisferro piscisferro changed the title table.apiEvent sortBy nor working properly table.apiEvent sortBy not working properly? Jan 16, 2020
@Romain59000
Copy link

Romain59000 commented May 14, 2020

this.columns = [
{ key: 'name', title: 'Nom', orderBy: 'asc' },
{ key: 'code', title: 'Code' }
];

Same problem with sort in columns array. OrderBy is always desc...

@ssuperczynski
Copy link
Owner

Sorry, for the late answer. I don't have as much time as before to develop the new features/fix bugs. I'll try to fix this bug as as soon as possible.

@and-yiannis
Copy link

I think the problem is that the orderBy function sets the order by calling setColumnOrder (the function that is used to flip the state from asc to desc and vice versa), ignoring the order value that was stored in the local storage.

RJiraya pushed a commit to RJiraya/ngx-easy-table that referenced this issue Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants