Skip to content

Commit bf180a2

Browse files
committed
update for search & default sorted column
1 parent 967146a commit bf180a2

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/app/app.component.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,15 @@ mat-sidenav {
119119
transform: rotate(45deg);
120120
-webkit-transform: rotate(45deg);
121121
top: calc(50% - .5rem);
122+
}
123+
124+
.form {
125+
min-width: 100%;
126+
max-width: 100%;
127+
padding: .5rem;
128+
width: 100%;
129+
}
130+
131+
.full-width {
132+
width: 100%;
122133
}

src/app/app.component.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
<chips-autocomplete-component [allItems]=allItems [placeholder]=placeholder></chips-autocomplete-component>
88
</div>
99
-->
10+
11+
<form class="form">
12+
<mat-form-field class="full-width">
13+
<input matInput placeholder="Text" value="" (keyup.enter)="search($event.target.value)">
14+
</mat-form-field>
15+
</form>
16+
1017
<div>
11-
<h1>Sort</h1>
1218
<mat-button-toggle-group name="fontStyle" aria-label="Font Style" fxLayout="row">
1319
<mat-button-toggle fxLayout='column' fxFlex="33.3" *ngFor="let column of sortcolumns; let i = index" [class.asc]="sortedOrder == sortedAsc" [class.desc]="sortedOrder == sortedDesc" [value]="column.value" (click)="sort(column)">{{column.text}}</mat-button-toggle>
1420
</mat-button-toggle-group>

src/app/app.component.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export class AppComponent {
2222
allItems: string[] = ['Apple', 'Lemon', 'Lime', 'Orange', 'Strawberry'];
2323

2424
// for sort
25+
defaultSoredColumn = 'ts';
2526
sortcolumns = [{
2627
key: 'default',
27-
value: 'ts',
28+
value: this.defaultSoredColumn,
2829
text: 'Default'
2930
}, {
3031
key: 'title',
@@ -87,13 +88,14 @@ export class AppComponent {
8788
this.mode = 'determinate';
8889
}
8990

90-
getList(page: any, size: any, orderBy?: string, order?: string) {
91+
getList(page: any, size: any, orderBy?: string, order?: string, text?: string) {
9192
this.startProgress();
9293
const params = new HttpParams()
9394
.set('page', page)
9495
.set('size', size)
95-
.set('orderBy', orderBy)
96-
.set('direction', order ? order : this.sortedAsc);
96+
.set('orderBy', orderBy || this.defaultSoredColumn)
97+
.set('direction', order || this.sortedAsc)
98+
.set('query', text || '');
9799
this.httpService
98100
.get<APIResponse<Item>>(environment.getAll, params)
99101
.subscribe((response: any) => {
@@ -125,4 +127,8 @@ export class AppComponent {
125127
this.getList(1, this.pageSize, this.sortedColumn, this.sortedOrder);
126128
}
127129

130+
search(text: string) {
131+
this.getList(1, this.pageSize, this.sortedColumn, this.sortedOrder, text);
132+
}
133+
128134
}

src/app/app.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AppComponent } from './app.component';
77
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
88
import { MatProgressBarModule, MatAutocompleteModule, MatIconModule, MatChipsModule,
99
MatFormFieldModule, MatPaginatorModule, MatTableModule, MatSortModule, MatSidenavModule,
10-
MatButtonModule, MatButtonToggleModule } from '@angular/material';
10+
MatButtonModule, MatButtonToggleModule, MatInputModule } from '@angular/material';
1111
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
1212
import { HttpClientModule } from '@angular/common/http';
1313

@@ -39,7 +39,8 @@ import { HttpService } from '../service/http.service';
3939
MatSortModule,
4040
MatSidenavModule,
4141
MatButtonModule,
42-
MatButtonToggleModule
42+
MatButtonToggleModule,
43+
MatInputModule
4344
],
4445
providers: [HttpService],
4546
bootstrap: [AppComponent]

0 commit comments

Comments
 (0)