Skip to content

Commit 0b6ea1d

Browse files
committed
feat(igxFor): Add input igxForOfTotalItemCount to be settable in template #4453
1 parent 2213cfc commit 0b6ea1d

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
141141
@Input()
142142
public igxForItemSize: any;
143143

144+
/**
145+
* The total count of the virtual data items, when using remote service.
146+
* Similar to the property totalItemCount, but this will allow setting the data count into the template.
147+
* ```html
148+
* <ng-template igxFor let-item [igxForOf]="data | async" [igxForOfTotalItemCount]="count | async"
149+
* [igxForContainerSize]="'500px'" [igxForItemSize]="'50px'"></ng-template>
150+
* ```
151+
*/
152+
@Input()
153+
get igxForTotalItemCount(): number {
154+
return this.totalItemCount;
155+
}
156+
set igxForTotalItemCount(value: number) {
157+
this.totalItemCount = value;
158+
}
144159
/**
145160
* @hidden
146161
*/

src/app/shared/remote.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { HttpClient } from '@angular/common/http';
66
@Injectable()
77
export class RemoteService {
88

9+
totalCount: Observable<number>;
10+
_totalCount: BehaviorSubject<number>;
911
remoteData: Observable<any[]>;
1012
_remoteData: BehaviorSubject<any[]>;
1113
url = `https://services.odata.org/V4/Northwind/Northwind.svc/Products`;
@@ -14,6 +16,8 @@ export class RemoteService {
1416
constructor(private http: HttpClient) {
1517
this._remoteData = new BehaviorSubject([]);
1618
this.remoteData = this._remoteData.asObservable();
19+
this._totalCount = new BehaviorSubject(null);
20+
this.totalCount = this._totalCount.asObservable();
1721
}
1822

1923
nullData() {
@@ -31,6 +35,7 @@ export class RemoteService {
3135
)
3236
.subscribe(d => {
3337
this._remoteData.next(d['value']);
38+
this._totalCount.next(d['@odata.count']);
3439
if (cb) {
3540
cb(d);
3641
}

src/app/virtual-for-directive/virtual-for.sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
[igxForScrollOrientation]="'vertical'"
8181
[igxForContainerSize]='"500px"'
8282
[igxForItemSize]='"50px"'
83+
[igxForTotalItemCount]="totalCount | async"
8384
let-rowIndex="index" #virtDirRemote>
8485
<div style='height:50px;'>Index: {{rowIndex}}, ID: {{item.ProductID}}, Name : {{item.ProductName}}</div>
8586
</ng-template>

src/app/virtual-for-directive/virtual-for.sample.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class VirtualForSampleComponent implements OnInit, AfterViewInit {
1313
search1: string;
1414
data = [];
1515
remoteData: any;
16+
totalCount: any;
1617
options = {};
1718
prevRequest: any;
1819
itemSize = '100px';
@@ -45,6 +46,7 @@ export class VirtualForSampleComponent implements OnInit, AfterViewInit {
4546

4647
ngOnInit(): void {
4748
this.remoteData = this.remoteService.remoteData;
49+
this.totalCount = this.remoteService.totalCount;
4850
const data = [{
4951
key: 1,
5052
avatar: 'assets/images/avatar/1.jpg',
@@ -136,7 +138,7 @@ export class VirtualForSampleComponent implements OnInit, AfterViewInit {
136138

137139
ngAfterViewInit() {
138140
this.remoteService.getData(this.virtDirRemote.state, (data) => {
139-
this.virtDirRemote.totalItemCount = data['@odata.count'];
141+
//this.virtDirRemote.totalItemCount = data['@odata.count'];
140142
});
141143
}
142144
chunkLoading(evt) {

0 commit comments

Comments
 (0)