0

I'm working with angular material table, and im not able to populate the grid yet due to below error:

Error: Provided data source did not match an array, Observable, or DataSource

search.service.ts

GridSubmittedFilesList: IGridModel;
getFilesSubmitted(data: any): Observable<IGridModel> {
    return this.http.post<IGridModel>(this._url, JSON.stringify(data),
      { headers: { 'Content-Type': 'application/json' }, withCredentials: true });

  }

component.ts

export class ResultGridComponent implements OnInit {

  constructor(private searchSubmissionService: SearchSubmissionService) { }

  gridSubmittedFilesList: IGridModel;

  displayedColumns = ['report', 'business', 'location'];

  ngOnInit(): void {

    this.searchSubmissionService.searchSource$.subscribe(
      message => {
        this.sendPostReq(message);
      }
    );
  }

  sendPostReq(data: any): any {
    this.searchSubmissionService.getFilesSubmitted(data)
      .subscribe(data => this.gridSubmittedFilesList = data
    );

  }
}

IGridModel.ts

import { Result } from './Result';

export interface IGridModel {
 
    Result: Result
}

Result.ts

export interface Result {
    //grid
    ReportName: string;
    Business: number;
    Location: string;
}

result-grid.component.ts

<div class="mat-elevation-z8 div-expanded" style=" height: 58vh;">

    <!-- [hidden]="dataSource.data.length==0" -->
    <table mat-table [dataSource]="gridSubmittedFilesList" matSort 
           class="schedule-status-table">
        <ng-container matColumnDef="report">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Request Id </th>
            <td mat-cell *matCellDef="let row"> {{row.Result.ReportName}} </td>
        </ng-container>

I'm not able to realize what I'm doing wrong... I did the same way in order to populate dropdownLists and no issues, but with this Material grid it is not possible.. Any idea? Thank you!

1
  • Sorry but I don't see the declaration for this.gridSubmittedFilesList in ResultGridComponent ; where is that part? Also here's a link that may help... dev.to/jwp/angular-material-table-in-20-minutes-15f4 Commented Oct 21, 2020 at 14:31

1 Answer 1

1

You have to initialize gridSubmittedFilesList as an empty array because it's null now or just set *ngIf for this table until gridSubmittedFilesList.length !== 0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.