Skip to content

Commit 47ea885

Browse files
author
Konstantin Dinev
committed
Fixing the grid
1 parent c2c3adf commit 47ea885

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/app/grid/grid.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
<igx-column [header]="'Rank'" [field]="'Id'" [sortable]="true" >
2020
<ng-template igxCell let-col="column" let-ri="rowIndex" let-item="item">
2121
<div>
22-
<span *ngIf="ri < 1 && grid1.state.paging.index == 0 && sortedByTrackProgress" class="cup">
22+
<span *ngIf="grid1.state.paging.index == 0 && sortedByTrackProgress && item === 1" class="cup">
2323
<svg id="circle" height="24" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2424
<image x="0" y="0" height="24" width="24" xlink:href="assets/images/grid/3iP.svg" />
2525
</svg>
2626
</span>
27-
<span *ngIf="ri > 0 && ri < 3 && grid1.state.paging.index == 0 && sortedByTrackProgress" class="cup">
27+
<span *ngIf="grid1.state.paging.index == 0 && sortedByTrackProgress && (item === 2 || item === 3)" class="cup">
2828
<svg id="circle" height="24" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2929
<image x="0" y="0" height="24" width="24" xlink:href="assets/images/grid/3hz.svg" />
3030
</svg>

src/app/grid/grid.component.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class GridComponent implements OnInit {
4343
this.live = true;
4444
this.disabled = false;
4545
this.sortedByTrackProgress = true;
46-
4746
this.SortByTrackProgress();
4847
}
4948
private SortByTrackProgress() {
@@ -62,7 +61,9 @@ export class GridComponent implements OnInit {
6261

6362
private tickerFunc(tick) {
6463
if (tick % 3 === 0) {
65-
const idx = this.getRandomNumber(5, 0);
64+
const size = this.grid1.dataContainer.transformedData.length - 1;
65+
const min = Math.min(5, size);
66+
const idx = this.getRandomNumber(min, 0);
6667
const newValue = this.grid1.getCell(idx, 'TrackProgress').dataItem + 15;
6768

6869
if (newValue >= 100) {
@@ -96,8 +97,10 @@ export class GridComponent implements OnInit {
9697
}
9798
private resetPositions() {
9899
let index = 0;
100+
const size = this.grid1.dataContainer.transformedData.length - 1;
101+
const min = Math.min(size, 6);
99102

100-
while (index < 6) {
103+
while (index < min) {
101104
this.grid1.updateCell(index, 'Position', 'current');
102105
index++;
103106
}
@@ -143,9 +146,21 @@ export class GridComponent implements OnInit {
143146
});
144147

145148
if (this.grid1.paginator.isFirst && this.sortedByTrackProgress) {
146-
rowElements.slice(1, 4).forEach((tr: HTMLElement) => tr.style.backgroundColor = '#E7F5FE' );
149+
const size = this.grid1.dataContainer.transformedData.length - 1;
150+
const min = Math.min(3, size);
151+
for (let i = 0; i < min; i++) {
152+
if (this.grid1.getRow(i).record.Id < 4) {
153+
this.grid1.getRow(i).element.style.backgroundColor = '#E7F5FE';
154+
}
155+
}
147156
}
148157
}, 1);
158+
159+
if (this.sortedByTrackProgress) {
160+
this.localData.forEach((value, index) => {
161+
value.Id = index + 1;
162+
});
163+
}
149164
}
150165

151166

@@ -157,7 +172,6 @@ export class GridComponent implements OnInit {
157172
const direction = event.direction;
158173

159174
this.sortedByTrackProgress = false;
160-
161175
if (event.column.field === 'Id' && direction === 0) {
162176
const column = this.grid1.getColumnByField('TrackProgress');
163177
this.grid1.sortColumn(column, SortingDirection.Desc);

0 commit comments

Comments
 (0)