Primeng: Lazy loaded data tables never set multiSortMeta

Created on 1 Dec 2016  路  2Comments  路  Source: primefaces/primeng

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

Plunkr Case (Bug Reports)
Don't have time to put a plunkr together at the moment, but it doesn't seem like it would be particularly useful for this bug

Current behavior
If a data table is set to use lazy loading, the user is expected to handle sorting based on the information emitted in the onLazyLoad and/or onSort events; however, the multiSortMeta field is never set for a lazy loaded table. As seen in the code snippet below (from datatable.ts sort() function), addSortMeta is not called if the table is lazy. Therefore, multiSortMeta will always be undefined, unless the attribute is set by the caller, which means that whichever component subscribes to the onLazyLoad event cannot know how to sort the data.

            if(this.lazy) {
                this.stopFilterPropagation = true;
                this.onLazyLoad.emit(this.createLazyLoadMetadata());
            }
            else {
                if(this.sortMode == 'multiple') {
                    if(!this.multiSortMeta||!metaKey) {
                        this.multiSortMeta = [];
                    }

                    this.addSortMeta({field: this.sortField, order: this.sortOrder});
                    this.sortMultiple();
                }
                else {
                    this.sortSingle();
                }
            }

            this.onSort.emit({
                field: this.sortField,
                order: this.sortOrder,
                multisortmeta: this.multiSortMeta
            });

It seems that addSortMeta should be called before the onLazyLoad event is emitted, as below

            if(this.sortMode == 'multiple') {
                    if(!this.multiSortMeta||!metaKey) {
                        this.multiSortMeta = [];
                    }
                    this.addSortMeta({field: this.sortField, order: this.sortOrder});
            }
            if(this.lazy) {
                this.stopFilterPropagation = true;
                this.onLazyLoad.emit(this.createLazyLoadMetadata());
            }
            else if (this.sortMode == 'multiple'){
                this.sortMultiple();
            }
            else {
                this.sortSingle();
            }

            this.onSort.emit({
                field: this.sortField,
                order: this.sortOrder,
                multisortmeta: this.multiSortMeta
            });

Expected behavior
multiSortMeta should be set before the onLazyLoad event is emitted so that the component listening for the event knows how the data should be sorted.

Minimal reproduction of the problem with instructions

Don't have time to make a plunker right now, but you should just need to create a datatable that is lazy and has sort mode set to multiple. Kind of hard to make a functional example, since the problem is that there isn't enough information emitted with the onLazyLoad event to actually sort properly in this scenario.

What is the motivation / use case for changing the behavior?
Be able to multisort on lazy loaded tables

Please tell us about your environment:

Windows 10, Visual Studio 2015 Enterprise Edition, using npm

  • Angular version: 2.0.0

  • PrimeNG version: 1.0.0

  • Browser:
    At least Chrome 54. Haven't tried in anything else, but doesn't seem browser-specific

  • Language:
    Typescript 2.0.8

  • Node (for AoT issues):
    5.8.0

defect

Most helpful comment

I have the same problem. Getting this fixed is critical for me. I have 400,000+ records to display so I cannot use eager loading and searching those records is too difficult without being able to sort on more than 1 column.

All 2 comments

The issue is reproduced for PrimeNG v1.1.4

I have the same problem. Getting this fixed is critical for me. I have 400,000+ records to display so I cannot use eager loading and searching those records is too difficult without being able to sort on more than 1 column.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

just-paja picture just-paja  路  3Comments

cyberrranger picture cyberrranger  路  3Comments

Helayxa picture Helayxa  路  3Comments

pchristou picture pchristou  路  3Comments

mitosandov picture mitosandov  路  3Comments