pagination & pagination demo 1st done
This commit is contained in:
parent
b810163be3
commit
7c67d81439
@ -0,0 +1,3 @@
|
|||||||
|
<pagination [totalItems]="pages.length" [itemsPerPage]="1" [maxSize]="10"
|
||||||
|
(pageChanged)="pageChanged($event)"
|
||||||
|
[boundaryLinks]='true' previousText="‹" nextText="›" firstText="«" lastText="»"></pagination>
|
@ -0,0 +1,26 @@
|
|||||||
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
|
import { IDataSource } from '@poweredsoft/data';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'psbx-ds-pagination',
|
||||||
|
templateUrl: './data-source-pagination.component.html',
|
||||||
|
styleUrls: ['./data-source-pagination.component.scss']
|
||||||
|
})
|
||||||
|
export class DataSourcePaginationComponent implements OnInit {
|
||||||
|
|
||||||
|
@Input() pages: any[];
|
||||||
|
@Input() dataSource: IDataSource<any>
|
||||||
|
|
||||||
|
totalItems:Number;
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
pageChanged(event){
|
||||||
|
this.dataSource.page = event.page;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { DataSourcePaginationComponent } from './data-source-pagination/data-source-pagination.component';
|
||||||
|
import { PaginationModule } from 'ngx-bootstrap/pagination';
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [DataSourcePaginationComponent],
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
PaginationModule.forRoot(),
|
||||||
|
],
|
||||||
|
exports:[DataSourcePaginationComponent]
|
||||||
|
})
|
||||||
|
export class psbxPaginationModule { }
|
@ -6,3 +6,5 @@ export * from './lib/command-modal/command-modal.module';
|
|||||||
export * from './lib/command-modal/directives/command-modal.directive';
|
export * from './lib/command-modal/directives/command-modal.directive';
|
||||||
export * from './lib/form-group-command-modal/form-group-command-modal.module';
|
export * from './lib/form-group-command-modal/form-group-command-modal.module';
|
||||||
export * from './lib/form-group-command-modal/directives/form-group-command-modal.directive';
|
export * from './lib/form-group-command-modal/directives/form-group-command-modal.directive';
|
||||||
|
export * from './lib/pagination/psbxPagination.module';
|
||||||
|
export * from './lib/pagination/data-source-pagination/data-source-pagination.component';
|
@ -23,6 +23,10 @@ const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: 'form-group',
|
path: 'form-group',
|
||||||
loadChildren: () => import('./form-group-modal-demo/form-group-modal-demo.module').then(m => m.FormGroupModalDemoModule)
|
loadChildren: () => import('./form-group-modal-demo/form-group-modal-demo.module').then(m => m.FormGroupModalDemoModule)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'pagination-demo',
|
||||||
|
loadChildren: ()=> import('./pagination-demo/pagination-demo.module').then(m => m.PaginationDemoModule)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" routerLink="form-group">Form Group Modal</a>
|
<a class="nav-link" routerLink="form-group">Form Group Modal</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" routerLink="pagination-demo">pagination Demo</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-10" style="padding-top: 5px">
|
<div class="col-lg-10" style="padding-top: 5px">
|
||||||
|
15
src/app/pagination-demo/pagination-demo-routing.module.ts
Normal file
15
src/app/pagination-demo/pagination-demo-routing.module.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { Routes, RouterModule } from '@angular/router';
|
||||||
|
import { PaginationDemoComponent } from './pagination-demo/pagination/pagination-demo.component';
|
||||||
|
|
||||||
|
|
||||||
|
const routes: Routes = [{
|
||||||
|
path: '',
|
||||||
|
component: PaginationDemoComponent
|
||||||
|
}];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forChild(routes)],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class PaginationDemoRoutingModule { }
|
22
src/app/pagination-demo/pagination-demo.module.ts
Normal file
22
src/app/pagination-demo/pagination-demo.module.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
|
import { PaginationDemoRoutingModule } from './pagination-demo-routing.module';
|
||||||
|
import { PaginationDemoComponent } from './pagination-demo/pagination/pagination-demo.component';
|
||||||
|
import { DataGridModule } from '@poweredsoft/ngx-cdk-ui';
|
||||||
|
import { FormGroupCommandModalModule,psbxPaginationModule, CommandModalModule } from '@poweredsoft/ngx-bootstrap';
|
||||||
|
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [PaginationDemoComponent],
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
PaginationDemoRoutingModule,
|
||||||
|
psbxPaginationModule,
|
||||||
|
DataGridModule,
|
||||||
|
CommandModalModule,
|
||||||
|
FormsModule
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class PaginationDemoModule { }
|
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
<ps-data-grid [dataSource]="merchantDataSource" [(columns)]="columns"
|
||||||
|
tableClasses="table table-sm table-dark table-striped table-bordered">
|
||||||
|
<ng-container *psDataGridHeader>
|
||||||
|
<button class="btn-warning btn" psbxCommandModal commandTitle="Adding a new merchant" commandText="Add"
|
||||||
|
[dataSource]="merchantDataSource" command="addMerchant" [template]="theModal">Create a new record</button>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container psDataGridCol="id">
|
||||||
|
<div *psDataGridColHeader>ID</div>
|
||||||
|
<div *psDataGridCell="let model">{{model.id}}</div>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container psDataGridCol="name">
|
||||||
|
<div *psDataGridColHeader>Name</div>
|
||||||
|
<div *psDataGridCell="let model">{{model.name}}</div>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container psDataGridCol="address">
|
||||||
|
<div *psDataGridColHeader>Address</div>
|
||||||
|
<div *psDataGridCell="let model">{{model.address}}</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container psDataGridCol="commands">
|
||||||
|
<ng-container *psDataGridColHeader>Actions</ng-container>
|
||||||
|
<ng-container *psDataGridCell="let model">
|
||||||
|
<button class="btn-warning btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'" commandText="Update"
|
||||||
|
[dataSource]="merchantDataSource" command="changeMerchantName" [model]="model" [template]="changeName">Change name</button>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container *psDataGridFooter>
|
||||||
|
<psbx-ds-pagination [dataSource]="merchantDataSource" [pages]="pages"></psbx-ds-pagination>
|
||||||
|
</ng-container>
|
||||||
|
</ps-data-grid>
|
||||||
|
|
||||||
|
<ng-template #changeName let-command let-loading="loading">
|
||||||
|
New Name
|
||||||
|
<input type="text" [attr.disabled]="loading" [(ngModel)]="command.newName" placeholder="Entermerchant new name" class="form-control">
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #theModal let-command let-loading="loading">
|
||||||
|
Name
|
||||||
|
<input type="text" [attr.disabled]="loading" [(ngModel)]="command.name" placeholder="Enter a merchant name" class="form-control">
|
||||||
|
Address
|
||||||
|
<input type="text" [attr.disabled]="loading" [(ngModel)]="command.address" placeholder="Enter the merchant's address" class="form-control">
|
||||||
|
</ng-template>
|
@ -0,0 +1,51 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { IDataSource } from '@poweredsoft/data';
|
||||||
|
import { IMerchant } from 'src/app/data/services/IMerchant';
|
||||||
|
import { MerchantService } from 'src/app/data/services/merchant.service';
|
||||||
|
import { IModelFormCreateEvent } from '@poweredsoft/ngx-bootstrap';
|
||||||
|
import { FormBuilder, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ps-pagination',
|
||||||
|
templateUrl: './pagination-demo.component.html',
|
||||||
|
styleUrls: ['./pagination-demo.component.scss']
|
||||||
|
})
|
||||||
|
export class PaginationDemoComponent implements OnInit {
|
||||||
|
columns = ['id','name', 'address', 'commands']
|
||||||
|
merchantDataSource: IDataSource<IMerchant>;
|
||||||
|
constructor(private merchantService: MerchantService){
|
||||||
|
this.merchantDataSource = this.createDataSource();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pages:any;
|
||||||
|
|
||||||
|
newMerchant(name: string) {
|
||||||
|
this.merchantDataSource.executeCommandByName('addMerchant', {
|
||||||
|
name: name
|
||||||
|
}).subscribe(
|
||||||
|
res => {
|
||||||
|
alert('it worked!');
|
||||||
|
this.merchantDataSource.refresh();
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log(err);
|
||||||
|
alert('failed');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
createDataSource(): IDataSource<IMerchant> {
|
||||||
|
return this.merchantService.createDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.merchantDataSource.refresh();
|
||||||
|
this.merchantDataSource.data$.subscribe(newData => {
|
||||||
|
if (newData)
|
||||||
|
this.pages = new Array(newData.numberOfPages);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user