Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Can't get data to display properly #1650

@stephenmatthews

Description

@stephenmatthews

Hi, im new to angular and I cant seem to get my datatable working properly. Any help would be greatly appreciated!

This is what i'm currently getting - it just says No data available in table and i cant get the sorting or search to work either
Screenshot 2022-04-11 at 12 59 26

component.html

<table datatable [dtOptions]="dtOptions" datatable="ng" class="row-border hover table table-striped table-bordered">
        <thead>
          <tr>
            <th>Name</th>
            <th>Company</th>
            <th>Email</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let client of clients">
            <td>{{ client?.clientName }}</td>
            <td>{{ client?.clientCompany }}</td>
            <td>{{ client?.clientEmail }}</td>
            <td>
              <button class="solid">Edit</button>
              <button class="danger">Delete</button>
            </td>
          </tr>
        </tbody>
    
      </table>

component.ts

dtOptions: DataTables.Settings = {};
  clients: any = [];
  dtTrigger: Subject<any> = new Subject<any>(); 

  constructor(
    public webService: WebService,
    private renderer: Renderer2,
    private router: Router,
    private httpClient: HttpClient
  ) { }

  ngOnInit(): void {
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 2
    };
    this.webService.getClients()
      .subscribe(data => {
        this.clients = data;
        console.log(this.clients)
        // Calling the DT trigger to manually render the table
        this.dtTrigger.next;
      });
  }


  ngOnDestroy(): void {
    // Do not forget to unsubscribe the event
    this.dtTrigger.unsubscribe();
  }

example data used
Screenshot 2022-04-11 at 12 54 40

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions