Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTableFooterComponent: "Cannot read property 'toLocaleString' of undefined" #838

Closed
AdamVig opened this issue Jun 26, 2017 · 11 comments
Closed

Comments

@AdamVig
Copy link

AdamVig commented Jun 26, 2017

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, post on Stackoverflow or Gitter

Current behavior

When initializing a data table with the below code, the below error is printed to the console.

<ngx-datatable class="material"
    [rows]="configs"
    [columns]="columns"
    [limit]="10"
    [headerHeight]="50"
    [footerHeight]="50">
</ngx-datatable>

The following error (and its corresponding DebugContext) is logged to the console four times when I load my page:

DataTableFooterComponent.html:20 ERROR TypeError: Cannot read property 'toLocaleString' of undefined
    at Object.eval [as updateRenderer] (DataTableFooterComponent.html:20)
    at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13144)
    at checkAndUpdateView (core.es5.js:12293)
    at callViewAction (core.es5.js:12651)
    at execEmbeddedViewsAction (core.es5.js:12609)
    at checkAndUpdateView (core.es5.js:12289)
    at callViewAction (core.es5.js:12651)
    at execComponentViewsAction (core.es5.js:12583)
    at checkAndUpdateView (core.es5.js:12294)
    at callViewAction (core.es5.js:12651)

This is the value of the component property in the DebugContext printed to the console:
image

This is confusing to me, because all of the component's values seem to be defined. Also confusing because DataTableFooterComponent.html:20 points to a line without any bindings on it, but that could just be a sourcemap problem:
image

Despite the errors, the footer seems to render correctly:
image

Expected behavior

The table displays without logging any errors to the console.

Reproduction of the problem

The problem happens on page load. Could not reproduce in Plunker. Seems to be related to this commit.

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

This is a bug.

Please tell us about your environment:

macOS 10.12.5
VS Code 1.13.1
node 8.0.0, npm 5.0.0
Angular CLI 1.1.3

  • Table version: 9.3.0
  • Angular version: 4.2.4
  • Browser: [all | Chrome 58.0.3029.110 (64-bit) | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]
@dannyvenier
Copy link

Seems from the error that selectedCount is null at some point - could it be that selectedCount is not initialized when the view part of the footer is rendered (on first load) and that is the source of the error. Then when selectedCount gets set, the binding kicks in and all is good. However, looking at what you posted, I would expect the footer to say something like "0 selected / 29 total". It is hard to tell without much of the code. Also possible that the error message is pointing at rowCount rather than selectedCount, or more likely both since you saw duplicates of the error. Either way, when the error is thrown, the property is null, likely prior to its initialization. Take a look at the lifecycle of selectedCount and rowCount to see when they get initialized.

@LuisUrrutia
Copy link

LuisUrrutia commented Jul 5, 2017

Have you solved it? I have the same problem and i don't know how to proceed

EDIT:
Well, I have a class called Paging and it have the property count, and i was expecting that this value was zero (zero value of a number) when i initialized it without any value, but it doesn't and that was causing the error.

Before:

this.paging = new Paging();

After:

this.paging = new Paging();
this.paging.count = 0;

@IbrahimElkhatib
Copy link

I faced this issue, in our case it was my teammate mistake, she was initializing the rows as empty object not array

@ikilled
Copy link

ikilled commented Jul 7, 2017

I also faced this issue and figured out that the problem was that I was providing to DataTable an Object containing multiple Objects (rows) but I should provide an Array containing multiple Objects.

More specifically, in my case the cause of problem was that the API providing the rows was filtering some results out of all DB results. This filtering caused that the array of rows didn't have sequential keys any more
(but something like 2,3,5,8,..) so PHP automatically added "explicit" keys to my array. I solved it by removing these keys with php's function array_values() before API sending the response to my front-end Angular App.

@AdamVig
Copy link
Author

AdamVig commented Jul 7, 2017

I ended up moving to Angular Material's MdTable component, which was released this week. It lacks some of the features that NgxDatatable has, but has significantly better scroll performance and will grow more feature-rich over time.

Because of this, I'm unsubscribing from notifications on this issue.

@anbiniyar
Copy link

anbiniyar commented Dec 23, 2017

FWIW I had the same issue. It seems like I get into this issue if I use lodash cloneDeep() to clone the array for the rows. If I don't clone the array, it works just fine for me.

@hungtruongquoc
Copy link

@LuisUrrutia Thanks. I applied the same solution.

@mxchange
Copy link

mxchange commented Jun 7, 2018

I have a similar issues where in some cases the table would show nothing and no error when count is not passed, in other cases it will throw an error.
Should the count be defaulted to the length of the rows when not passed?

@tonivj5
Copy link

tonivj5 commented Jul 14, 2018

Any news on this?

@techno2mahi
Copy link

Pls refer this
solved

@AdamVig AdamVig closed this as completed Jan 21, 2019
@Usama-Nazir
Copy link

ERROR 💥 TypeError: Cannot read properties of undefined (reading 'toLocaleString')
at eval (eval at wrap (D:\trybase-master\node_modules\pug-runtime\wrap.js:6:10), :21:1511)
at eval (eval at wrap (D:\trybase-master\node_modules\pug-runtime\wrap.js:6:10), :31:4)
at template (eval at wrap (D:\trybase-master\node_modules\pug-runtime\wrap.js:6:10), :34:7)
at exports.renderFile (D:\trybase-master\node_modules\pug\lib\index.js:454:38)
at exports.renderFile (D:\trybase-master\node_modules\pug\lib\index.js:444:21)
at exports.__express [as engine] (D:\trybase-master\node_modules\pug\lib\index.js:493:11)
at View.render (D:\trybase-master\node_modules\express\lib\view.js:135:8)
at tryRender (D:\trybase-master\node_modules\express\lib\application.js:657:10)
at Function.render (D:\trybase-master\node_modules\express\lib\application.js:609:3)
at ServerResponse.render (D:\trybase-master\node_modules\express\lib\response.js:1039:7) {
statusCode: 500,
status: 'error'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests