Problem with rowgroup and filters

UI Components for Angular
Post Reply
nodo@portel.es
Posts: 4
Joined: 18 Jul 2018, 14:42

14 Sep 2018, 11:36

Hello

I'm trying to group the rows in a table with filters, but when I succeeded the filters broke. It seems like the grouping rows are filtered as well, but not always.

I've modified the example in the live demo to show the issue: https://stackblitz.com/edit/rowgroup-with-filters

Without filters:

Vin Year Color
Ford
123 2012 Red
122 2012 Red
Renault
125 2012 Red
BMW
666 2012 Yellow
Audi
128 2012 Red

Filtering by VIN (12):
Vin Year Color
Ford
123 2012 Red
122 2012 Red
Renault
125 2012 Red
128 2012 Red

Audi disappeared. Could anyone tell me why?

Thanks.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

18 Sep 2018, 22:28

I think you need to rebuild the rowGroupMetadata on filter, I could not test the following but here is an idea.

Code: Select all

<p-table ... (onFilter)="onFilter($event)"

Code: Select all

onFilter(event) {
   this.updateRowGroupMetaData(event.filteredValue);
}

updateRowGroupMetaData(data) {
        this.rowGroupMetadata = {};
        if (data) {
            for (let i = 0; i < data.length; i++) {
                let rowData = data[i];
                let brand = rowData.brand;
                if (i == 0) {
                    this.rowGroupMetadata[brand] = { index: 0, size: 1 };
                }
                else {
                    let previousRowData = this.cars[i - 1];
                    let previousRowGroup = previousRowData.brand;
                    if (brand === previousRowGroup)
                        this.rowGroupMetadata[brand].size++;
                    else
                        this.rowGroupMetadata[brand] = { index: i, size: 1 };
                }
            }
        }
    }


nodo@portel.es
Posts: 4
Joined: 18 Jul 2018, 14:42

21 Sep 2018, 11:21

I improved the component with sorting combined with filters and row grouping:

https://stackblitz.com/edit/rowgroup-wi ... s-and-sort

I had to implement a custom sort because in the onSort event I don't have the sorted list. Is there a better way to do this?

Thank you.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests