Previously I pulled all the data from my Bitacora table, but now I need to work with Lazy , so as not to saturate with the data when loading, followed by the example of PrimeNg Table-Lazy . but I do not know how to work in the Lazy of PrimeNg in the Spring part, and how to send it from Angular 6 . And I'm already two days with this situation and the project is delayed, I thank you beforehand.
This is my code.
list-itacora.omponent.ts
export class ListBitacoraComponent implements OnInit { public cols: any[]; //Columnas public bitacora: Array; //Se carga datos de Bitacora
public bitacoraLazy: Array; //Se carga el Lazy de bitacora public totalRecords: number; public loading: boolean; constructor(private bitacoraService: BitacoraService) {} public ngOnInit() {
this.load(); this.cols = [ { field: 'id', header: 'ID' }, { field: 'ip', header: 'Ip' }, { field: 'usuario', header: 'Usuario' }, { field: 'formulario', header: 'Formulario' }, { field: 'accion', header: 'Accion' }, { field: 'descripcion', header: 'Descripcion' }, { field: 'nivel', header: 'Nivel' }, { field: 'fecha', header: 'Fecha' } ];
this.loading = true; } private load(): void{ this.bitacoraService.get().subscribe(resp => { if (resp.code == OK) { this.bitacora = resp.value;
this.messageValidate.showSuccess(BITACORA_SUCCESS_HEAD,resp.message);
this.totalRecords = this.bitacora.length;
} else { this.bitacora = []; this.messageValidate.showSuccess(BITACORA_ERROR_HEAD,resp.message); } }); } loadCarsLazy(event: LazyLoadEvent) { this.loading = true; setTimeout(() => { if (this.bitacora) { this.bitacoraLazy = this.bitacora.slice(event.first, (event.first + event.rows)); this.loading = false; console.log("Exito lazy: "+this.bitacoraLazy); }else{ console.log("Error Lazy: "+this.bitacoraLazy); } }, 1000); }
bitacora.service.ts
export class BitacoraService { private URL: string = URL_SERVE_BACKEND; constructor(private http: HttpClient) { } public get(): Observable { return this.http.get(this.URL + "/getBitacora"); } }
In the loadCarsLazy (event: LazyLoadEvent) method, I am working the same as nothing with the data already obtained in this.bitacora, but I would like to work directly with the backend
This is my code in the Backend Srping elk
BitacoraController.java
@RestController public class BitacoraController { private static final Logger log = LogManager.getLogger(ClienteController.class); @Autowired private BitacoraService bitacoraService; protected ObjectMapper mapper; private String nombreFormulario = Formulario.REGISTRAR_CLIENTE.getNombre(); @GetMapping("/getBitacora") public BaseResponse get() { try { return new BaseResponse(HttpStatus.OK.value(), Mensajes.BITACORA_SUCCESS_GET, bitacoraService.get(), ""); } catch (Exception e) { String message = Mensajes.BITACORA_ERROR_GET + nombreFormulario; log.error(BaseLog.error(message), e); return new BaseResponse(HttpStatus.NOT_ACCEPTABLE.value(), message, null, ""); } }}
BitacoraDao.java
public interface BitacoraDao extends JpaRepository{ /** * Se obtiene todos los datos de bitacora */ @Query("SELECT b FROM MuBitacora b ORDER BY b.id DESC") List get(); }