primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Sorting and lazy loading don't work together

Open jgiro opened this issue 9 years ago • 8 comments

Latest version of Angular 2 and PrimeNG. Sorting works until I add lazy loading:

<p-dataTable [value]="cars" selectionMode="single" 
[(selection)]="selectedCar" (onRowSelect)="onRowSelect($event)" 
[rows]="10" [paginator]="true" [pageLinks]="4" [rowsPerPageOptions]="[5,10,20,50,100]" 
[responsive]="true" resizableColumns="true" [lazy]="true"
[totalRecords]="totalRecords" (onLazyLoad)="loadCarsLazy($event)">
    <p-column field="idd" header="ID" [sortable]="true">
        <template let-idd let-car="rowData" pTemplate="body">
            <div [style.background-color]="getStyle(car.idd)">
              <span [style.color]="black" >{{car[idd.field]}}</span>
            </div>
        </template>
    </p-column>    
    <p-column field="vin" header="Vin" [sortable]="true"></p-column>
    <p-column field="year" header="Year" [sortable]="true"></p-column>
    <p-column field="brand" header="Brand" [sortable]="true"></p-column>
    <p-column field="color" header="Color" [sortable]="true"></p-column>
</p-dataTable>

jgiro avatar Dec 25 '16 20:12 jgiro

still nothing ? did somebody find a trick to make them work together ?

umens avatar Feb 21 '17 01:02 umens

You do know that in the lazy loading case, the SERVER needs to handle sorting? The dataTable only sends the properties to be sorted on to the server. The docs could be more explicit.

olingerc avatar Feb 21 '17 16:02 olingerc

oh ok, that makes sense ! it's obvious. what a dumb I am. Thanks anyway for the help. This issues should be close I think.

umens avatar Feb 21 '17 17:02 umens

@jgiro I hope you find the solution. if not : when lazyloading, the sort value (field and order) are send to the event (onLazyLoad) and not from the (sortFunction) like the usual way.

from the lazyload doc

loadData(event: LazyLoadEvent) {
    //event.first = First row offset
    //event.rows = Number of rows per page
    //   --->   event.sortField = Field name to sort in single sort mode
    //   --->   event.sortOrder = Sort order as number, 1 for asc and -1 for dec in single sort mode
    //multiSortMeta: An array of SortMeta objects used in multiple columns sorting. Each SortMeta has field and order properties.
    //filters: Filters object having field as key and filter value, filter matchMode as value
    this.cars = //do a request to a remote datasource using a service and return the cars that match the lazy load criteria
}

umens avatar Feb 22 '17 23:02 umens

In lazy mode, you should do the sorting at backend.

cagataycivici avatar Jun 19 '17 10:06 cagataycivici

Sorting is not working with Virtual scroll (Lazy loading) in PrimeNG data table.Actually with large data set ,primeNg table become hang, for this resolution I have implemented Virtual scroll(Lazy loading). But there is a problem that Sorting is not working in lazy load.

Also,I tried custom sorting for that but still not working.Actually my custom sort function is not working with Lazy loading.Any solution ?

Is It fixed in recent PrimeNG release ?

akashdeepg12 avatar Aug 01 '17 05:08 akashdeepg12

is Lazy Load equivalent to On Demand Load? I am a bit confused about Lazy Load.

bhaidar avatar Sep 05 '17 14:09 bhaidar

Why did you close the incident without any solution. I have same issue and after landing here I saw this. What a great PrimeFace team. Should I create new ticket in list of more than 900 open issues?

kunjan343 avatar Oct 15 '21 17:10 kunjan343