mariuszfoltak / angular2-datatable

DataTable - Simple table component with sorting and pagination for Angular2
202 stars 183 forks source link

search filer Problem - Property 'first_name' does not exist on type '{}' #137

Closed parthpatwala closed 6 years ago

parthpatwala commented 6 years ago

In my Angular-cli project I've this code to implemented datatable with search filter. I've used tutorial given using loadsh. http://plnkr.co/edit/grhag1P85teN4ftggkms?p=preview

I want to add search filter and it showed me this error in updateData function. Property 'first_name' does not exist on type '{}'. Is it problem with typescript or loadsh version or something else?

export class UsersComponent implements OnInit {

    public users: any = [];
    public filteredData: any;
    public filterQuery = "";
    public rowsOnPage = 10;
    public sortBy = "first_name";
    public sortOrder = "asc";

    ngOnInit() {
        this.authService.getUsersList(userData).subscribe(data => {
            var res = data.response;
            this.users = this.users;
            this.filteredData = res.data;
        });
    }

    public updateData(query:string) {
        if(query) {
            this.filteredData = _.filter(this.users, (a)=>a.first_name.indexOf(query)>=0);
        } else {
            this.filteredData = this.users;
        }
    }
}

Here is my package.json file with loadsh version

"dependencies": {
  "angular2-datatable": "^0.6.0",
  "lodash": "^4.17.4",
},
"devDependencies": {

  "@types/lodash": "^4.14.50",
  "typescript": "~2.0.3"
}
parthpatwala commented 6 years ago

Sorry. Solved my issue by updating this code this.filteredData = _.filter(this.users, (a)=>(a as any).first_name.indexOf(query)>=0);