primeng icon indicating copy to clipboard operation
primeng copied to clipboard

p-dataTable does not render when multiSortMeta is set

Open ASK83 opened this issue 9 years ago • 6 comments

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) Yesterday the table was broken so couldn't add a plunker for the bug. But now here is the plunker that shows the p-table throws find error as described below.

http://plnkr.co/edit/43HqrN?p=preview

Current behavior addition of [multiSortMeta] to my table causes primeng below error. If I don't set the multiSortMeta the table renders correctly but without the default sorts applied to the table. Error: EXCEPTION: Error in ./TableComponent class TableComponent - inline template:5:2 caused by: # Cannot read property 'find' of undefined ErrorHandler.handleError @ error_handler.js:51 next @ application_ref.js:373 schedulerFn @ async.js:98 SafeSubscriber.__tryOrUnsub @ Subscriber.js:223 SafeSubscriber.next @ Subscriber.js:172 Subscriber._next @ Subscriber.js:125 Subscriber.next @ Subscriber.js:89 Subject.next @ Subject.js:55 EventEmitter.emit @ async.js:84 NgZone.triggerError @ ng_zone.js:331 onHandleError @ ng_zone.js:292 ZoneDelegate.handleError @ zone.js:246 Zone.runTask @ zone.js:154 ZoneTask.invoke @ zone.js:345 error_handler.js:53 ORIGINAL EXCEPTION: Cannot read property 'find' of undefined ErrorHandler.handleError @ error_handler.js:53 next @ application_ref.js:373 schedulerFn @ async.js:98 SafeSubscriber.__tryOrUnsub @ Subscriber.js:223 SafeSubscriber.next @ Subscriber.js:172 Subscriber._next @ Subscriber.js:125 Subscriber.next @ Subscriber.js:89 Subject.next @ Subject.js:55 EventEmitter.emit @ async.js:84 NgZone.triggerError @ ng_zone.js:331 onHandleError @ ng_zone.js:292 ZoneDelegate.handleError @ zone.js:246 Zone.runTask @ zone.js:154 ZoneTask.invoke @ zone.js:345 error_handler.js:56 ORIGINAL STACKTRACE: ErrorHandler.handleError @ error_handler.js:56 next @ application_ref.js:373 schedulerFn @ async.js:98 SafeSubscriber.__tryOrUnsub @ Subscriber.js:223 SafeSubscriber.next @ Subscriber.js:172 Subscriber._next @ Subscriber.js:125 Subscriber.next @ Subscriber.js:89 Subject.next @ Subject.js:55 EventEmitter.emit @ async.js:84 NgZone.triggerError @ ng_zone.js:331 onHandleError @ ng_zone.js:292 ZoneDelegate.handleError @ zone.js:246 Zone.runTask @ zone.js:154 ZoneTask.invoke @ zone.js:345 error_handler.js:57 TypeError: Cannot read property 'find' of undefined at DataTable.ngDoCheck (datatable.js:285) at Wrapper_DataTable.ngDoCheck (wrapper.ngfactory.js:516) at View_TableComponent1.detectChangesInternal (component.ngfactory.js:406) at View_TableComponent1.AppView.detectChanges (view.js:438) at View_TableComponent1.DebugAppView.detectChanges (view.js:633) at ViewContainer.detectChangesInNestedViews (view_container.js:71) at CompiledTemplate.proxyViewClass.View_TableComponent0.detectChangesInternal (component.ngfactory.js:98) at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:438) at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:633) at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (view.js:423) at View_BlockComponent2.detectChangesInternal (component.ngfactory.js:284) at View_BlockComponent2.AppView.detectChanges (view.js:438) at View_BlockComponent2.DebugAppView.detectChanges (view.js:633) at ViewContainer.detectChangesInNestedViews (view_container.js:71) at CompiledTemplate.proxyViewClass.View_BlockComponent0.detectChangesInternal (component.ngfactory.js:138)

I tracked down the error to a change in primeng table code as below:

working version (previous version of PrimeNg): else if(!this.lazy && (this.sortField||this.multiSortMeta)) { if(this.sortMode == 'single') this.sortSingle(); else if(this.sortMode == 'multiple') this.sortMultiple(); }

Not working version: ` else if(!this.lazy && (this.sortField||this.multiSortMeta)) {
if(!this.sortColumn) { this.sortColumn = this.columns.find(col => col.field === this.sortField && col.sortable === 'custom'); }

            if(this.sortMode == 'single')
                this.sortSingle();
            else if(this.sortMode == 'multiple')
                this.sortMultiple();
        }

`

Based on the error received it appears this.cloumns is not defined and find could not apply on it at this point.

Expected behavior Primeng 1.0.0 was working and applying the metaSort highlighted to the corresponding fields.

Minimal reproduction of the problem with instructions Here is my table component structure: <p-dataTable #table [exportFilename]="description" [value]="filterData$ | async" sortMode="multiple" [multiSortMeta]="defaultSortOrders" [globalFilter]="gb" [selectionMode]="selected" [(selection)]="selectedRow" (onRowSelect)="onRowSelect($event)" [rows]="rowsPerPageOptions[0]" [paginator]="(filterData$ | async)?.length > rowsPerPageOptions[0] ? true: false" [pageLinks]="5" [rowsPerPageOptions]="rowsPerPageOptions" paginatorPosition="top"> </p-dataTable>

What is the motivation / use case for changing the behavior?

Please tell us about your environment: Windows 10

  • Angular version: 2.4.1
  • PrimeNG version: 2.1.1
  • Browser: all
  • Language: TypeScript [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version =

ASK83 avatar Dec 22 '16 14:12 ASK83

I have the same issue with "sortField" on the dataTable on 1.1.2.

MaximeMorin avatar Dec 23 '16 19:12 MaximeMorin

Yep. "sortField" doesn't work on [email protected], too.

Still throws "Cannot read property 'find' of undefined" here https://github.com/primefaces/primeng/blob/1.1.3/components/datatable/datatable.ts#L633

ilianiv avatar Jan 04 '17 08:01 ilianiv

Similar situation occurs in 1.1.4 - problem with sortField still exists.

marcinkaszuba avatar Jan 07 '17 17:01 marcinkaszuba

This issue is a blocking issue for us, too. This is a critical issue, existing for 18 day already, and 3 new versions were already released (1.1.2-4) since it's reported. We are still on 1.0.1 because each version of primeng introduces a new blocking bug for us. I think the most powerful feature of primeng is the datatable, it deserves more attention by the developers.

ribizli avatar Jan 09 '17 12:01 ribizli

Fixed via #1789

cagataycivici avatar Jan 11 '17 18:01 cagataycivici

@cagataycivici, any plan to release this? I see 2.0, but when it is planned? We are still on 1.0.1 due to several issues were introduced during fixing others, which is nonsense.

ribizli avatar Jan 19 '17 09:01 ribizli