Topic: table search don't work with remote data

mviross free asked 4 years ago


enter image description here

I have this error when am trying to search for data in the table. When I tried with local data it works.


Arkadiusz Idzikowski staff commented 4 years ago

Please provide example code on which we will be able to reproduce this problem.


mviross free answered 4 years ago


    import {Component, HostListener, OnInit, ViewChild} from '@angular/core';
import {Observable} from 'rxjs';
import {UsersService} from '../../services/users.service';
import {map} from 'rxjs/operators';
import {MdbTableDirective} from "ng-uikit-pro-standard";

@Component({
  selector: 'app-users',
  templateUrl: './users.component.html',
  styleUrls: ['./users.component.scss']
})
export class UsersComponent implements OnInit {
  @ViewChild(MdbTableDirective, { static: true })
  mdbTable:MdbTableDirective;
  users:any=[];

  searchText: string = '';
  previous: string;


  constructor(private userService:UsersService) { }


  @HostListener('input')
  oninput() {
    this.searchItems();
  }
  ngOnInit() {

    this.users= this.userService.getUsers().pipe(
      map(
        changes=>changes.map(
          ({payload:{doc}})=>{
            const data = doc.data();
            const id=doc.id;
            return {id,...data}
          }
        )
      )
    );

    this.mdbTable.setDataSource(this.users);
    this.previous =this.mdbTable.getDataSource();
  }



  searchItems() {
    const prev =this.mdbTable.getDataSource();
    if (!this.searchText) {
      this.mdbTable.setDataSource(this.previous);
      this.users =this.mdbTable.getDataSource();
    }
    if (this.searchText)
    {
      this.users =this.mdbTable.searchLocalDataBy(this.searchText);
      this.mdbTable.setDataSource(prev);
    }
  }
}


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 8.8.1
  • Device: mac
  • Browser: chrome
  • OS: macos
  • Provided sample code: No
  • Provided link: No