question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set property 'offset' of undefined when filtering

See original GitHub issue

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 I type in the filter box, it gives the error: “Cannot set property ‘offset’ of undefined”

Expected behavior It is supposed to filter the rows.

Reproduction of the problem http://plnkr.co/edit/BP5Zw2

[import { Component, ViewChild } from '@angular/core';
import { DatatableComponent } from '../../../node_modules/@swimlane/ngx-datatable/src/components/datatable.component';

@Component({
    selector: 'app-school-list',
    template: `
    <input type='text'
      placeholder='Type to filter the name column...'
      (keyup)='updateFilter($event)' />
    <ngx-datatable
      #table
      [columns]="columns"
      [footerHeight]="50"
      [limit]="5"
      [rows]='rows'>
    </ngx-datatable>
  `
})

export class SchoolListComponent {
    temp = [];
    columns = [
        { prop: 'name' },
        { name: 'Gender' },
        { name: 'Company' }
    ];
    rows = [
        { name: 'Austin', gender: 'Male', company: 'Swimlane' },
        { name: 'Bobby', gender: 'Male', company: 'KFC' },
        { name: 'Christina', gender: 'Female', company: 'Burger King' },
        { name: 'Dustin', gender: 'Male', company: 'Swimlane' },
        { name: 'Ellie', gender: 'Female', company: 'KFC' },
        { name: 'Flower', gender: 'Female', company: 'Burger King' },
        { name: 'Gordon', gender: 'Male', company: 'Swimlane' },
        { name: 'Houston', gender: 'Male', company: 'KFC' },
        { name: 'Ian', gender: 'Male', company: 'Burger King' }
    ];

    @ViewChild(DatatableComponent) table: DatatableComponent;

    constructor() {
        this.temp = this.rows;
    }

    updateFilter(event) {
        const val = event.target.value.toLowerCase();

        const temp = this.temp.filter(function (d) {
            return d.name.toLowerCase().indexOf(val) !== -1 || !val;
        });

        this.rows = temp;
        this.table.offset = 0;
    }
}

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

Please tell us about your environment:

  • Table version: 0.8.x 9.1.0

  • Angular version: 2.0.x 4.0.2

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] Chrome v57

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript 2.1.5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
hotdog1987commented, May 18, 2017

First off, I think you need to import like this: import { DatatableComponent } from '@swimlane/ngx-datatable/src/components/datatable.component';

Secondly, I think you need to write the View Child like this: @ViewChild('table') table: DatatableComponent;

@amcdnl The example demo (https://github.com/swimlane/ngx-datatable/blob/master/demo/basic/filter.component.ts) is making reference to ‘#table’ from the template. So, I think the above syntax works.

It worked for me.

1reaction
hotdog1987commented, Sep 25, 2019

@NivethaMuthukumar Its clear from the error that your webpack.config is not loading this ngx-datatables module and therefore, typescript compilation is failing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngx datatables 'Cannot set property 'offset' of undefined' when ...
I am trying to use ngx-datatables in my angular 2 app. I tried following the example: https://github.com/swimlane/ngx-datatable/blob/master/demo ...
Read more >
ngx datatables 'Cannot set property 'offset' of undefined' when ...
Coding example for the question ngx datatables 'Cannot set property 'offset' of undefined' when filtering-angular.js.
Read more >
How to avoid undefined offset error in PHP ? - GeeksforGeeks
isset() function : This function checks whether the variable is set and is not equal to null. It also checks if array or...
Read more >
Uncaught TypeError: Cannot read property 'offset' of undefined
And here is the Error ( It crashes at the first console log) tsc-emit.js:37 Uncaught TypeError: Cannot read property 'offset' of undefined
Read more >
HTML DOM Style filter Property - W3Schools
Applies a blur effect to the image. A larger value will create more blur. If no value is specified, 0 is used. brightness(%),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found