Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Using sortMode="multiple" in p-table #7615


User avatar
0
ipservant created

Hi,

I'd like to use sortMode="multiple" (see here https://primefaces.org/primeng/#/table/sort), where you can select multiple columns to sort by when you CTRL+Click them.

I added sortMode here:

<p-table #dataTable
                                     (onLazyLoad)="getAktenkorrespondenzen($event)"
                                     [value]="primengTableHelper.records"
                                     sortMode="multiple"
                                     rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                     [paginator]="false"
                                     [lazy]="true"
                                     [scrollable]="true"
                                     ScrollWidth="100%"
                                     [responsive]="primengTableHelper.isResponsive"
                                     [resizableColumns]="primengTableHelper.resizableColumns">

Now I'm able to select multiple columns, but this.primengTableHelper.getSorting(this.dataTable) remains undefined.

Single sorting works fine as soon as I remove sortMode.

Do you have an idea how to correctly implement multi sort?

Thank you in advance! IPS


2 Answer(s)
  • User Avatar
    1
    ipservant created

    I found a solution by myself that I wanted to share with you, feel free to let me know what you think of it. I extended PrimengTableHelper.ts with:

        getMultiSorting(table: Table): string {
            let sorting;
            if (table.multiSortMeta != undefined && table.multiSortMeta.length > 0) {
                sorting = '';
                for (let i = 0; i < table.multiSortMeta.length; i++) {
                    if (table.multiSortMeta[i]) {
                        sorting += table.multiSortMeta[i].field;
                        if (table.multiSortMeta[i].order === 1) {
                            sorting += ' ASC';
                        } else if (table.multiSortMeta[i].order === -1) {
                            sorting += ' DESC';
                        }
                        if ((i + 1) < table.multiSortMeta.length) {
                            sorting += ', ';
                        }
                    }
                }
            }
    

    Core then uses OrderBy:

    .OrderBy(input.Sorting ?? "id asc")
    

    Kind regards, IPS

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ips-ad

    Thank you for sharing this. We can also include this into AspNet Zero.

    Thanks again.