Issue
Can anyone tell me what I'm doing wrong here?
I have a material date range entry, and on it's own it looks fine. I have checked everything I can, however I am at a loss as I cannot see any reason for this to be the case.
<p>Works</p>
<mat-form-field appearance="fill" class="z1">
<mat-label>Enter a date range</mat-label>
<mat-date-range-input [rangePicker]="picker">
<input matStartDate placeholder="Start date" [(ngModel)]="start">
<input matEndDate placeholder="End date" [(ngModel)]="end">
</mat-date-range-input>
<mat-hint>MM/DD/YYYY – MM/DD/YYYY</mat-hint>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>
<button mat-button (click)="search()">Search</button>
<!--<mat-form-field>
<mat-table></mat-table>
</mat-form-field>-->
However, uncommenting the table, with or without the form field, removes that formatting.
<p>Works</p>
<mat-form-field appearance="fill" class="z1">
<mat-label>Enter a date range</mat-label>
<mat-date-range-input [rangePicker]="picker">
<input matStartDate placeholder="Start date" [(ngModel)]="start">
<input matEndDate placeholder="End date" [(ngModel)]="end">
</mat-date-range-input>
<mat-hint>MM/DD/YYYY – MM/DD/YYYY</mat-hint>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>
<button mat-button (click)="search()">Search</button>
<mat-form-field>
<mat-table></mat-table>
</mat-form-field>
For reference, this is my imports.
@NgModule({
declarations: [
AppComponent,
PrintBookingComponent,
PrintBookingDetailsComponent,
OrderSearchComponent,
OrderBookingComponent,
PageNotFoundComponent,
HomeComponent
],
imports: [
MatDatepickerModule,
MatInputModule,
MatFormFieldModule,
MatNativeDateModule,
MatButtonModule,
MatRippleModule,
BrowserAnimationsModule,
MatMenuModule,
MatTabsModule,
MatTableModule,
MatIconModule,
BrowserModule,
GraphQLModule,
HttpClientModule,
ApolloModule,
FormsModule,
AppRoutingModule,
],
providers: [
{
provide: APOLLO_FLAGS,
useValue: {
useInitialLoading: true, // enable it here
},
},{
provide: APOLLO_OPTIONS,
useFactory: (httpLink: HttpLink) => {
return {
cache: new InMemoryCache(),
link: httpLink.create({
uri: 'http://localhost:3000/graphql/',
}),
};
},
deps: [HttpLink],
}],
bootstrap: [AppComponent]
})
export class AppModule { }
Solution
First of all don't wrap with mat-form-field
because mat-form-field
work only with form like input, button
etc. Then add dataSource, row, header, column
like below code
HTML: `
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef>No.</th>
<td mat-cell *matCellDef="let element">{{ element.position }}</td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">{{ element.name }}</td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef>Weight</th>
<td mat-cell *matCellDef="let element">{{ element.weight }}</td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef>Symbol</th>
<td mat-cell *matCellDef="let element">{{ element.symbol }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
`
TS:
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
Answered By - Dinesh Kumar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.