ayudame con una aplicacion spring boot angular, quiero filtrar por fechas, te dare un…
- User
ayudame con una aplicacion spring boot angular, quiero filtrar por fechas, te dare un ejemplo y luego me diras que hago, ventas: Record<string, any>[] = []; ventasFiltradas: Record<string, any>[] = [];
datatable { title: 'Fecha', data: 'fecha', render: (data) => { return new Date(data).toLocaleString(); }, },
formulario(): void { this.formVentaFecha = this.fb.group({ minFecha: [null], maxFecha: [null], }); this.formVentaFecha.valueChanges.subscribe(() => { this.refreshTable(); }); }
filtrarVentasPorFechas(): void { const { minFecha, maxFecha } = this.formVentaFecha.value; if (minFecha || maxFecha) { console.log(minFecha); console.log(maxFecha); this.ventasFiltradas = this.ventas.filter((venta) => { const ventaFechaSinTiempo = new Date( new Date(venta['fecha']).setHours(0, 0, 0, 0) ) .toISOString() .split('T')[0]; return ( (!minFecha || minFecha <= ventaFechaSinTiempo) && (!maxFecha || ventaFechaSinTiempo <= maxFecha) ); }); } else { this.ventasFiltradas = this.ventas; } } refreshTable() { const tabla = $('#tablaVenta').DataTable(); if (tabla) { tabla.ajax.reload(); } }
ngOnDestroy(): void { this.dtTrigger.unsubscribe(); }
printDiv(): void { window.print(); } } eso esel ejemplo,luego te dire de que debes hacerlo siguiendo ese ejemplo, analiza y responde en lineas
- Assistant