Datatable lazyload stops filtering/sorting working.

UI Components for React
Post Reply
stefan1968
Posts: 9
Joined: 03 Dec 2017, 22:17

02 May 2018, 09:07

If I enable lazyLoad on the datatable component i.e: -
lazy={true}
onLazyLoad={this.onLazyLoad}


Then column filtering and column sorting stops working.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

10 May 2018, 14:05

Hi,

You need to write custom sorting and filtering methods for this issue. Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking onLazyLoad callback everytime paging, sorting and filtering happens. Please see comments in our example;
https://www.primefaces.org/primereact/#/datatable/lazy

Code: Select all

onLazyLoad(event) {
        this.setState({loading: true});
        /* In a real application, make a remote request to load data using state metadata from event
         * event.first = First row offset
         * event.rows = Number of rows per page
         * event.sortField = Field name to sort with
         * event.sortOrder = Sort order as number, 1 for asc and -1 for dec
         * filters: FilterMetadata object having field as key and filter value, filter matchMode as value */
        
        //imitate db connection over a network
        setTimeout(() => {
            if(this.datasource) {
                this.setState({
                    cars: this.datasource.slice(event.first, (event.first + event.rows)),
                    loading: false
                });
            }
        }, 250);
    }

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests