swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

Throws when list is empty and sort is pressed #444

Open aegyed91 opened 7 years ago

aegyed91 commented 7 years ago

I'm submitting a ... (check one with "x")

[x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior

Got a datatable with external sorting enabled, with custom header templates. If the column is sortable, and the table body contains no rows (showing the emptyMessage: 'No data to display'). And the user decides to sort the 0 rows. It will throw on this line: https://github.com/swimlane/ngx-datatable/blob/master/src/components/body/body.component.ts#L258 because this.scroller is undefined.

stack trace:

vendor.bundle.js?7088:87703 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ vendor.bundle.js?7088:87703
next @ vendor.bundle.js?7088:64486
schedulerFn @ vendor.bundle.js?7088:66568
SafeSubscriber.__tryOrUnsub @ vendor.bundle.js?7088:5410
SafeSubscriber.next @ vendor.bundle.js?7088:5359
Subscriber._next @ vendor.bundle.js?7088:5312
Subscriber.next @ vendor.bundle.js?7088:5276
Subject.next @ vendor.bundle.js?7088:24382
EventEmitter.emit @ vendor.bundle.js?7088:66554
NgZone.triggerError @ vendor.bundle.js?7088:53926
onHandleError @ vendor.bundle.js?7088:53887
ZoneDelegate.handleError @ vendor.bundle.js?7088:131775
Zone.runTask @ vendor.bundle.js?7088:131683
ZoneTask.invoke @ vendor.bundle.js?7088:131874
vendor.bundle.js?7088:87704 TypeError: Cannot read property 'setOffset' of undefined
    at DataTableBodyComponent.webpackJsonp.696.DataTableBodyComponent.updateOffsetY (main.bundle.js?7088:7723)
    at DatatableComponent.webpackJsonp.700.DatatableComponent.onColumnSort (main.bundle.js?7088:9241)
    at View_DatatableComponent1.handleEvent_0 (/NgxDatatableModule/DatatableComponent/component.ngfactory.js:74)
    at SafeSubscriber.schedulerFn [as _next] (vendor.bundle.js?7088:66580)
    at SafeSubscriber.__tryOrUnsub (vendor.bundle.js?7088:5410)
    at SafeSubscriber.next (vendor.bundle.js?7088:5359)
    at Subscriber._next (vendor.bundle.js?7088:5312)
    at Subscriber.next (vendor.bundle.js?7088:5276)
    at EventEmitter.Subject.next (vendor.bundle.js?7088:24382)
    at EventEmitter.emit (vendor.bundle.js?7088:66554)
    at DataTableHeaderComponent.webpackJsonp.705.DataTableHeaderComponent.onSort (main.bundle.js?7088:10037)
    at View_DataTableHeaderComponent2.handleEvent_0 (/NgxDatatableModule/DataTableHeaderComponent/component.ngfactory.js:107)
    at SafeSubscriber.schedulerFn [as _next] (vendor.bundle.js?7088:66580)
    at SafeSubscriber.__tryOrUnsub (vendor.bundle.js?7088:5410)
    at SafeSubscriber.next (vendor.bundle.js?7088:5359)

This is easy to solve, chk if scroller is defined.

amcdnl commented 7 years ago

I believe someone made a PR for this recently, if not can make add pr that chk plz?