Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPage event emitted when sorting single column #6734

Closed
biologeek opened this issue Oct 23, 2018 · 9 comments
Closed

onPage event emitted when sorting single column #6734

biologeek opened this issue Oct 23, 2018 · 9 comments

Comments

@biologeek
Copy link

biologeek commented Oct 23, 2018

I'm submitting a ... (check one with "x")

[X ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Code example

Definition of my table :

 <div class="mag-datagrid table-responsive table-bordered">
            <p-table [loading]="criteriaSelectedMeasuresLoader" 
            [paginator]="true" 
            [rows]="rowsPerTablePage" 
            [totalRecords]="pagingInformationForCriteriaTable?.totalElements" 
            (onLazyLoad)="loadNextPage($event)"
            [columns]="tableColumns" 
            [value]="criteriaSelectedMeasures$ | async" 
            [lazy]="true"
            class="table-striped table-bordered"
            (sortFunction)="customSort($event)"
            [customSort]="true">
              <ng-template pTemplate="header" let-columns>
                <tr>
                  <th *ngFor="let col of columns" [pSortableColumn]="col.field">
                    <p-sortIcon [field]="col.field" ariaLabel="Activate to sort" ariaLabelDesc="Activate to sort in descending order" ariaLabelAsc="Activate to sort in ascending order"></p-sortIcon>
                    {{col.label}}
                  </th>
                  <th>Sélection</th>
                </tr>
              </ng-template>
...

In TS the 2 callback functions :

    customSort($event: SortEvent) {
        console.log($event);
        if ($event.field === 'qualificationStr'){
            return;
        } else {
            const sort: Sort = new Sort();
            sort.sortDirection = $event.order === 1 ? SortDirection.ASC : SortDirection.DESC;
            sort.sortField = SortableField[this.tableColumns.filter(a => a.field === $event.field).map(a => a.backId)[0]];
            this.store.dispatch(new GetMeasureDefinitionsAction(this.selectedSearchFilter, this.currentPage, this.rowsPerTablePage, sort))
        }
    }
    
    loadNextPage($event: LazyLoadEvent) {
        this.currentPage = $event.first / $event.rows;
        this.criteriaSelectedMeasuresLoader = true;
        let currentFilter = null;
        this.store.select(a => a.filters.current).subscribe(f => currentFilter = f);
        this.store.dispatch(new GetMeasureDefinitionsAction(currentFilter, $event.first/$event.rows, $event.rows));
    }

Current behavior
When using sorting and paging with lazy loading, column sorting action emits an onPage event.

Edit: More exactly, the event emitted is well a Sor Event object but callback method called is the one defined for the LazyLoadEvent, while it should be

Similar to #3408 but with TurboTable and in version 6.1.4

Expected behavior
Sorting action hsould emit a SortEvent and call associated callback function

Minimal reproduction of the problem with instructions
Create a turbotable with both sorting and paging events and associated functions.

Please tell us about your environment:

  • Angular version: 6.1.0

  • PrimeNG version: 6.1.4

  • Browser: Chrome 60. Didn't test for other browsers

  • Language: TypeScript 2.7.2

  • Node (for AoT issues): 8.12

@cghislai
Copy link

I expect to receive a LazyLoadEvent on sorting, so that I can fetch the page records from backend.
Im not sure how the sortFunction should behave with lazy loading, and it sounds to me it should not be allowed. My interpretation of the documentation is that it is intended to use when you have all records (no lazy loading) but need a custom sorting algorithm..

@Michel73
Copy link

I have the same problem with PrimeNG version: 7.1.2
Clicking on sort icon emits the onLazyLoad-event.

@Michel73
Copy link

Now, I found in the documentation

by invoking onLazyLoad callback everytime paging, sorting and filtering happens.

That means when you use [lazy]=true then always the onLazyLoad-event is emitted and never the sortFunction-event. Unfortunately that is not clearly documented.
The onLazyLoad-event contains also the sortOrder (1=asc, 2=desc).

@fhljys
Copy link
Contributor

fhljys commented Aug 17, 2019

Have you resolve this issue? How can we separate sort from another event?

@cghislai
Copy link

@fhljys if you use lazy-mode, then you can use onLazyLoad. Otherwise use onSort. See documentation at https://www.primefaces.org/primeng/#/table.

@fhljys
Copy link
Contributor

fhljys commented Aug 17, 2019

@cghislai . Thanks for your reply. But I want to know which is triggered by clicking sort, which is triggered by scroll event. Currently, virtual scroll has an issue that even horizontal scroll will trigger lazyLoadEvent. #7207

@cghislai
Copy link

@fhljys I guess you will have to use the workaround in that issue then - keep the last LazyLoadEvent in your component state, and check against it when the next event occurs to see if it should be discarded. AFAIK, no other event will be fired on column sort in lazy mode.

@fhljys
Copy link
Contributor

fhljys commented Aug 17, 2019

Finally, I decided to give up the p-sortIcon and write my own sort event handler. Then I just need to check the event.first to decide whether I should discarded this event.

@cagataycivici
Copy link
Member

It is suggested to do the loading at onLazyLoad in a lazy table, sorting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants