ayudame con la impresion en datatable- ajax y angular , tengo este inconveniente -…
- User
ayudame con la impresion en datatable- ajax y angular , tengo este inconveniente - @Component({ selector: 'app-inventario-almacen', templateUrl: './inventario-almacen.component.html', styleUrl: './inventario-almacen.component.css', }) export class InventarioAlmacenComponent implements AfterViewInit, OnInit, OnDestroy { dtOptions: Config = {}; dtTrigger = new Subject(); detalleSeccion: Record<string, any>[] = []; almacenes: Almacen[] = []; idalmacen: number | null = null; iconClass: string = '';
constructor(private almacenService: AlmacenService) {}
ngOnInit(): void { this.listarAlmacenes(); }
ngAfterViewInit(): void { this.initDataTable(); }
configDataTable(): void { this.dtOptions = { language: { url: 'https://cdn.datatables.net/plug-ins/2.0.8/i18n/es-ES.json', paginate: { first: '', last: '', next: '', previous: '', }, },
responsive: true, columnDefs: [ { responsivePriority: 1, targets: -1 }, { responsivePriority: 2, targets: 1 }, ], layout: { top2Start: 'buttons', topStart: 'pageLength', topEnd: 'search', }, buttons: { dom: { button: { tag: 'button', className: 'btn', }, }, buttons: [ { extend: 'excel', className: 'btn btn-outline-success', text: '<i class="bi bi-file-earmark-excel"></i>', titleAttr: 'Excel', messageTop: this.getDetalleSeccionMessage(), }, { extend: 'pdf', className: 'btn btn-outline-danger', text: '<i class="bi bi-file-earmark-pdf"></i>', titleAttr: 'PDF', }, ], }, };}
getDetalleSeccionMessage(): string { if (!this.detalleSeccion || this.detalleSeccion.length === 0) { console.log('detalleSeccion está vacío o no está definido'); return 'No hay datos disponibles'; } else { console.log('detalleSeccion tiene datos'); return 'Si hay datos' } }
initDataTable(): void { const that = this; this.dtOptions = { ...this.dtOptions, ajax: (dataTablesParameters: any, callback) => { this.listar(callback); },
columns: [ { title: 'ID', data: 'idproducto' }, { title: 'Producto', data: 'nombre_producto' }, { title: 'Categoria', data: 'nombre_categoria' }, { title: 'Stock', data: 'stock' }, ], };}
listarAlmacenes(): void { this.almacenService.listarAlmacenes().subscribe({ next: async (almacenes) => { this.almacenes = almacenes; this.idalmacen = this.almacenes[0].idalmacen; await this.obtenerDetallesSeccion(this.idalmacen); this.configDataTable(); setTimeout(() => { this.dtTrigger.next(this.dtOptions); }, 200); }, error: (error) => { console.error('Error al obtener almacenes', error); }, }); }
obtenerDetallesSeccion(idalmacen: number): Promise { return new Promise((resolve, reject) => { this.almacenService.obtenerDetalleSeccion(idalmacen).subscribe({ next: (detalles: Record<string, any>[]) => { this.detalleSeccion = detalles; console.log('Sección de detalles cargada:', this.detalleSeccion); resolve(detalles); }, error: (error) => { console.error('Error al obtener detalles de la sección', error); reject(error); }, }); }); }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.