Hi Team,
I was trying to work with the Async Pipe stuff in the SyncFusion Grid.
I tried the sample available in the documentation/online provided by SyncFusion and unfortunately, it didn't work for me.
My requirement for this task will be loading the Grid with the displaying content only and not the entire data from the WebAPI or WebServices.
By doing this, the pagination changes with the concerned data[In my case, I sent only 10 records at a time and the pagination for TotalPages, turned to 1 whereas I have 33 pages with 330 records]
I set the count as 330 and the list of data with 10 records, which failed in my case.
Any support will be appreciated and would save my day.
Thanks,
Raj
|
@Component({
selector: 'app-container',
template:`<ejs-grid [dataSource]='data | async' allowPaging= 'true' [pageSettings]='pageOptions' allowSorting= 'true' allowGrouping= 'true' (dataStateChange)= 'dataStateChange($event)'>
. . . . .
</ejs-grid>`
})
export class AppComponent {
constructor( private service: OrdersService) {
this.data = service;
}
public dataStateChange(state: DataStateChangeEventArgs): void {
this.service.execute(state);
}
public ngOnInit(): void {
this.pageOptions = { pageSize: 10, pageCount: 4 };
let state = { skip: 0, take: 12 };
this.service.execute(state);
}
}
|
|
. . . . .
export class OrdersService extends Subject<DataStateChangeEventArgs> {
private BASE_URL = 'http://services.odata.org/V4/Northwind/Northwind.svc/Orders';
. . . . .
public execute(state: any): void {
this.getData(state).subscribe(x => super.next(x));
}
protected getData(state: DataStateChangeEventArgs): Observable<DataStateChangeEventArgs> {
const pageQuery = `$skip=${state.skip}&$top=${state.take}`;
. . . . .
return this.http
.get(`${this.BASE_URL}?${pageQuery}${sortQuery}&$count=true`)
.map((response: any) => response.json())
.map((response: any) => (<DataResult>{
result: response['value'],
count: parseInt(response['@odata.count'], 10)
}))
.map((data: any) => data);
}
} |
Hi Anandraj,Thanks for contacting Syncfusion support,
We have validated your query and create a sample as per your requirement , In this sample Grid load only the displaying content(10 records) not load entire data from the Webservices. Grid will be refreshed with new data every time the Observable is resolved. Instead of assigning new Observable we need to resolve the same object with new data. kindly please refer the below code snippet and sample for more information,
app.component.ts
@Component({selector: 'app-container',template:`<ejs-grid [dataSource]='data | async' allowPaging= 'true' [pageSettings]='pageOptions' allowSorting= 'true' allowGrouping= 'true' (dataStateChange)= 'dataStateChange($event)'>. . . . .</ejs-grid>`})export class AppComponent {constructor( private service: OrdersService) {this.data = service;}
public dataStateChange(state: DataStateChangeEventArgs): void {this.service.execute(state);}
public ngOnInit(): void {this.pageOptions = { pageSize: 10, pageCount: 4 };let state = { skip: 0, take: 12 };this.service.execute(state);}}
Order.service.ts
. . . . .export class OrdersService extends Subject<DataStateChangeEventArgs> {private BASE_URL = 'http://services.odata.org/V4/Northwind/Northwind.svc/Orders';. . . . .public execute(state: any): void {this.getData(state).subscribe(x => super.next(x));}protected getData(state: DataStateChangeEventArgs): Observable<DataStateChangeEventArgs> {const pageQuery = `$skip=${state.skip}&$top=${state.take}`;. . . . .return this.http.get(`${this.BASE_URL}?${pageQuery}${sortQuery}&$count=true`).map((response: any) => response.json()).map((response: any) => (<DataResult>{result: response['value'],count: parseInt(response['@odata.count'], 10)})).map((data: any) => data);}}
Sample link : http://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-ng-grids-asynpipe-master746449206
Regards,
R.Dhivya
|
import { DataStateChangeEventArgs, Sorts,PredicateModel, DataResult, Search } from '@syncfusion/ej2-ng-grids'
import { Predicate } from '@syncfusion/ej2-data';
@Injectable()
export class OrdersService extends Subject<DataStateChangeEventArgs> {
. . . . . .
protected getData(state: DataStateChangeEventArgs): Observable<DataStateChangeEventArgs> {
const pageQuery = `$skip=${state.skip}&$top=${state.take}`;
let sortQuery: string = '';
let filterQuery: string = '';
if(state.where){
filterQuery = `&$filter=` + state.where.map((obj: PredicateModel) => {
return (<Predicate>obj).predicates.map((predicate)=> {
return predicate.operator === 'equal' ? `${predicate.field} eq ${predicate.value}` : `${predicate.operator}(tolower(${predicate.field}),'${predicate.value}')`;
}).reverse().join(' and ');
});
}
return this.http
.get(`${this.BASE_URL}?${pageQuery}${sortQuery}${filterQuery}&$count=true`)
.map((response: any) => response.json())
.map((response: any) => (<DataResult>{
result: response['value'],
count: parseInt(response['@odata.count'], 10)
}))
.map((data: any) => data);
}
} |
|
|
|
export class OrdersService extends Subject<DataStateChangeEventArgs> {
public execute(state: any, grid: any): void {
this.getData(state, grid).subscribe(x => super.next(x));
}
protected getData(state: DataStateChangeEventArgs, grid): Observable<DataStateChangeEventArgs> {
if (state.where) {
filterQuery = `&$filter=` + state.where.map((obj: PredicateModel) => {
return (<Predicate>obj).predicates.map((predicate) => {
if ((<any>predicate).predicates) {
if (<any>grid.getColumnByField((<any>predicate).predicates[0].field).type === 'date') { \\ get the type of column
return `((${(<any>predicate).predicates[0].field} gt ${(<any>predicate).predicates[0].value}) and (${(<any>predicate).predicates[1].field} lt ${(<any>predicate).predicates[1].value}))`;
. . . . .
}
}).reverse().join(' and ');
});
}
|