Skip to content

Commit

Permalink
fix_api(fe): Fixed paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudiaHdezPerez authored and Javi111003 committed Nov 23, 2024
1 parent 18c1915 commit 19d5c72
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
(optionSelected)="handleOptionSelected($event)"
>
</app-autocomplete>

<div class="grid-item export-button">
<button type="button" class="btn btn-primary custom-button">Descargar PDF</button>
<app-button></app-button>
</div>


<!-- Contenedor de la Tabla -->
<div class="grid-item table-container" *ngIf="showTable">
<app-table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MatPaginator } from '@angular/material/paginator';
templateUrl: './equipment.component.html',
styleUrls: ['./equipment.component.css']
})
export class EquipmentComponent implements OnInit, AfterViewInit {
export class EquipmentComponent implements OnInit {

constructor(private fb: FormBuilder) {
this.form = this.fb.group({
Expand All @@ -25,7 +25,6 @@ export class EquipmentComponent implements OnInit, AfterViewInit {
officeSelected: string = '';
// Example data for the table
dataSource: MatTableDataSource<any> = new MatTableDataSource([0]);
@ViewChild(MatPaginator) paginator: MatPaginator = [][0];

// Table Columns
displayedColumns: ConfigColumn[] = [
Expand All @@ -47,10 +46,6 @@ export class EquipmentComponent implements OnInit, AfterViewInit {
this.getCenterList();
}

ngAfterViewInit(): void {
this.dataSource.paginator = this.paginator;
}

/**
* Handles the change event of the first select control.
* Resets the second select control and updates its options based on the selected center.
Expand Down Expand Up @@ -107,9 +102,7 @@ export class EquipmentComponent implements OnInit, AfterViewInit {
{ position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F' },
{ position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne' },
];
this.dataSource = new MatTableDataSource(equipments);
this.dataSource.paginator = this.paginator;
console.log(this.dataSource);
this.dataSource.data = equipments;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-around;
justify-content: space-between;
}
.form-autocomplete {
width: 60%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
justify-items: left;
}
.form-buttons {
width: 18%;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
position:relative;
top: 8px;
left: 0;
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<div class="form-total-consumption">
<div class="form">
<app-autocomplete
[label]="'Centro de Trabajo'"
[options]="options"
(optionSelected)="handleOptionSelected($event)"
>
</app-autocomplete>
<div class="form-autocomplete">
<app-autocomplete
[label]="'Centro de Trabajo'"
[options]="options"
(optionSelected)="handleOptionSelected($event)"
>
</app-autocomplete>

<app-datepicker class="startDate"
[filter]="filterStartDate"
[label]="'Desde'"
(dateSelected)="handleDateSelected($event)"
></app-datepicker>
<app-datepicker class="startDate"
[filter]="filterStartDate"
[label]="'Desde'"
(dateSelected)="handleDateSelected($event)"
></app-datepicker>

<app-datepicker class="endDate"
[filter]="filterEndDate"
[label]="'Hasta'"
></app-datepicker>
<app-datepicker class="endDate"
[filter]="filterEndDate"
[label]="'Hasta'"
></app-datepicker>
</div>

<app-button
[label]="'Obtener'"
[function]="onClick.bind(this)"
>
</app-button>
<div class="form-buttons">
<app-button
[label]="'Consultar'"
[function]="onClick.bind(this)"
>
</app-button>

<app-button></app-button>
<app-button></app-button>
</div>
</div>

<br>

<div class="table" [class.hidden]="!isTableActive">
<app-table
[dataSource]="dataSource"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ export class TotalConsumptionComponent {

handleDateSelected(date: Date) {
this.receivedDate = date;
console.log('Fecha seleccionada:', this.receivedDate);
}

onClick() {
this.isTableActive = !this.isTableActive;
console.log(this.isTableActive);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@angular/core';
import { MatPaginatorIntl } from '@angular/material/paginator';

@Injectable()
export class PaginatorModifierComponent extends MatPaginatorIntl {
override itemsPerPageLabel = 'Elementos por página';
override nextPageLabel = 'Siguiente';
override previousPageLabel = 'Anterior';
override firstPageLabel = 'Primera página';
override lastPageLabel = 'Última página';
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
<tr mat-row *matRowDef="let row; columns: headings;"></tr>
</table>

<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]" aria-label="Select page of users"></mat-paginator>
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]" aria-label="Select page of users" showFirstLastButtons></mat-paginator>
</div>
9 changes: 6 additions & 3 deletions frontend/src/app/shared/components/table/table.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';

import { MatTableDataSource } from '@angular/material/table';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatPaginator, MatPaginatorIntl } from '@angular/material/paginator';
import { PaginatorModifierComponent } from './paginator-modifier.component';

export interface ConfigColumn {
title: string;
Expand All @@ -12,7 +12,10 @@ export interface ConfigColumn {
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrl: './table.component.css'
styleUrl: './table.component.css',
providers: [
{ provide: MatPaginatorIntl, useClass: PaginatorModifierComponent }
],
})
export class TableComponent implements OnInit, AfterViewInit {
@Input() dataSource: MatTableDataSource<any> = [][0];
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AsyncPipe } from '@angular/common';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { PaginatorModifierComponent } from './components/table/paginator-modifier.component';

@NgModule({
declarations: [
TableComponent,
ButtonComponent,
AutocompleteComponent,
DatepickerComponent
DatepickerComponent,
],
imports: [
CommonModule,
Expand Down

0 comments on commit 19d5c72

Please sign in to comment.