Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add refresh button to the footer #2184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/table/inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pagerLeftArrow: 'datatable-icon-left',
pagerRightArrow: 'datatable-icon-right',
pagerPrevious: 'datatable-icon-prev',
pagerNext: 'datatable-icon-skip'
refresh: 'datatable-icon-refresh'
```

## `externalPaging`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
[selectedCount]="selected.length"
[selectedMessage]="!!selectionType && messages.selectedMessage"
[pagerNextIcon]="cssClasses.pagerNext"
[refreshIcon]="cssClasses.refresh"
(page)="onFooterPage($event)"
(refresh)="onFooterRefresh($event)"
>
</datatable-footer>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export class DatatableComponent implements OnInit, DoCheck, AfterViewInit {
pagerLeftArrow: 'datatable-icon-left',
pagerRightArrow: 'datatable-icon-right',
pagerPrevious: 'datatable-icon-prev',
pagerNext: 'datatable-icon-skip'
pagerNext: 'datatable-icon-skip',
refresh: 'datatable-icon-refresh'
};

/**
Expand Down Expand Up @@ -436,6 +437,11 @@ export class DatatableComponent implements OnInit, DoCheck, AfterViewInit {
*/
@Output() page: EventEmitter<any> = new EventEmitter();

/**
* The table was refreshed
*/
@Output() refresh: EventEmitter<any> = new EventEmitter();

/**
* Columns were re-ordered.
*/
Expand Down Expand Up @@ -919,6 +925,28 @@ export class DatatableComponent implements OnInit, DoCheck, AfterViewInit {
}
}

/**
* The footer triggered a refresh event.
*/
onFooterRefresh(event: any) {
this.offset = event.page - 1;
this.bodyComponent.updateOffsetY(this.offset);

this.refresh.emit({
count: this.count,
pageSize: this.pageSize,
limit: this.limit,
offset: this.offset
});

if (this.selectAllRowsOnPage) {
this.selected = [];
this.select.emit({
selected: this.selected
});
}
}

/**
* Recalculates the sizes of the page
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('DataTableFooterComponent', () => {
[selectedCount]="selectedCount"
[selectedMessage]="selectedMessage"
[pagerNextIcon]="pagerNextIcon"
[refreshIcon]="refreshIcon"
(page)="onPageEvent($event)"
>
</datatable-footer>
Expand Down Expand Up @@ -243,6 +244,7 @@ class TestFixtureComponent {
pagerRightArrowIcon: string;
pagerPreviousIcon: string;
pagerNextIcon: string;
refreshIcon: string;
totalMessage: string;
footerTemplate: { template: TemplateRef<any> };
selectedCount: number;
Expand Down Expand Up @@ -274,6 +276,7 @@ class DataTablePagerComponentMock {
@Input() pagerRightArrowIcon: string;
@Input() pagerPreviousIcon: string;
@Input() pagerNextIcon: string;
@Input() refreshIcon: string;
@Input() page: number;
@Input() size: number;
@Input() count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { DatatableFooterDirective } from './footer.directive';
<div class="page-count" *ngIf="!footerTemplate">
<span *ngIf="selectedMessage"> {{ selectedCount?.toLocaleString() }} {{ selectedMessage }} / </span>
{{ rowCount?.toLocaleString() }} {{ totalMessage }}
<a role="button" aria-label="refresh" href="javascript:void(0)" (click)="reload()">
<i class="{{ refreshIcon }}"></i>
</a>
</div>
<datatable-pager
*ngIf="!footerTemplate"
Expand Down Expand Up @@ -53,13 +56,21 @@ export class DataTableFooterComponent {
@Input() pagerRightArrowIcon: string;
@Input() pagerPreviousIcon: string;
@Input() pagerNextIcon: string;
@Input() refreshIcon: string;
@Input() totalMessage: string;
@Input() footerTemplate: DatatableFooterDirective;

@Input() selectedCount: number = 0;
@Input() selectedMessage: string | boolean;

@Output() page: EventEmitter<any> = new EventEmitter();
@Output() refresh: EventEmitter<any> = new EventEmitter();

reload(): void {
this.refresh.emit({
page: this.curPage
})
}

get isVisible(): boolean {
return this.rowCount / this.pageSize > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class DatatableFooterDirective {
@Input() pagerRightArrowIcon: string;
@Input() pagerPreviousIcon: string;
@Input() pagerNextIcon: string;
@Input() refreshIcon: string;

@Input('template')
_templateInput: TemplateRef<any>;
Expand Down
22 changes: 22 additions & 0 deletions projects/swimlane/ngx-datatable/src/lib/themes/bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ bootstrap table theme
line-height: 50px;
height: 50px;
padding: 0 1.2rem;

a {
height: 22px;
min-width: 24px;
line-height: 22px;
padding: 4px 8px;
border-radius: 3px;
margin: 0 3px;
text-align: center;
vertical-align: top;
text-decoration: none;
vertical-align: middle;
color: #ededed;
font-size: 16px;

&:hover {
background-color: #545454;
font-weight: bold;
}
}
}
.datatable-pager {
margin: 0 10px;
Expand Down Expand Up @@ -80,6 +100,8 @@ bootstrap table theme
vertical-align: bottom;
color: #ededed;
}

.datatable-icon-refresh,
.datatable-icon-left,
.datatable-icon-skip,
.datatable-icon-right,
Expand Down
22 changes: 22 additions & 0 deletions projects/swimlane/ngx-datatable/src/lib/themes/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
line-height: 50px;
height: 50px;
padding: 0 1.2rem;

a {
height: 22px;
min-width: 24px;
line-height: 22px;
padding: 4px 8px;
border-radius: 3px;
margin: 0 3px;
text-align: center;
vertical-align: top;
text-decoration: none;
vertical-align: middle;
color: #72809b;
font-size: 16px;

&:hover {
background-color: #455066;
font-weight: bold;
}
}
}

.datatable-pager {
Expand Down Expand Up @@ -93,6 +113,8 @@
color: #72809b;
}


.datatable-icon-refresh,
.datatable-icon-left,
.datatable-icon-skip,
.datatable-icon-right,
Expand Down
23 changes: 23 additions & 0 deletions projects/swimlane/ngx-datatable/src/lib/themes/material.scss
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,28 @@ $datatable-summary-row-background-hover: #ddd !default;
line-height: 50px;
height: 50px;
padding: 0 1.2rem;


a {
height: 22px;
min-width: 24px;
line-height: 22px;
padding: 3px 12px;
border-radius: 3px;
margin: 6px 3px;
text-align: center;
vertical-align: top;
color: $datatable-pager-color;
text-decoration: none;
vertical-align: middle;
font-weight: bold;
font-size: 16px;

&:hover {
color: $datatable-pager-color-hover;
background-color: $datatable-pager-background-hover;
}
}
}

.datatable-pager {
Expand Down Expand Up @@ -382,6 +404,7 @@ $datatable-summary-row-background-hover: #ddd !default;
}
}

.datatable-icon-refresh,
.datatable-icon-left,
.datatable-icon-skip,
.datatable-icon-right,
Expand Down
1 change: 1 addition & 0 deletions src/app/basic/responsive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[scrollbarV]="true"
[rows]="rows"
(page)="onPage($event)"
(refresh)="onPage($event)"
>
<!-- Row Detail Template -->
<ngx-datatable-row-detail [rowHeight]="50" #myDetailRow (toggle)="onDetailToggle($event)">
Expand Down
1 change: 1 addition & 0 deletions src/app/basic/row-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[scrollbarV]="true"
[rows]="rows"
(page)="onPage($event)"
(refresh)="onPage($event)"
>
<!-- Row Detail Template -->
<ngx-datatable-row-detail [rowHeight]="100" #myDetailRow (toggle)="onDetailToggle($event)">
Expand Down
1 change: 1 addition & 0 deletions src/app/basic/virtual.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[rowHeight]="getRowHeight"
[scrollbarV]="true"
(page)="onPage($event)"
(refresh)="onPage($event)"
>
<ngx-datatable-column name="Name" [width]="300">
<ng-template let-value="value" ngx-datatable-cell-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[offset]="page.pageNumber"
[limit]="page.size"
(page)="setPage($event)"
(refresh)="setPage($event)"
>
</ngx-datatable>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/paging/paging-server.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[offset]="page.pageNumber"
[limit]="page.size"
(page)="setPage($event)"
(refresh)="setPage($event)"
>
</ngx-datatable>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/paging/paging-virtual.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface PageInfo {
[count]="totalElements"
[offset]="pageNumber"
(page)="setPage($event)"
(refresh)="setPage($event)"
>
</ngx-datatable>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/summary/summary-row-server-paging.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ColumnMode } from 'projects/swimlane/ngx-datatable/src/public-api';
[offset]="page.pageNumber"
[limit]="page.size"
(page)="setPage($event)"
(refresh)="setPage($event)"
>
</ngx-datatable>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ <h2>CSS mapping</h2>
<div class="icon datatable-icon-prev"></div>
<input type="text" readonly="readonly" value="prev" />
</li>
<li>
<div class="icon datatable-icon-refresh"></div>
<input type="text" readonly="readonly" value="refresh" />
</li>
</ul>
<h2>Character mapping</h2>
<ul class="glyphs character-mapping">
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@
.datatable-icon-prev::before {
content: '\72';
}

.datatable-icon-refresh::before {
content: '\1F5D8';
}