darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
447 stars 173 forks source link

i want use angular-datatable how to Integrate #96

Closed ncc0706 closed 5 years ago

ncc0706 commented 5 years ago

https://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way

ncc0706 commented 5 years ago

I Solved it!

spring-data-jpa-datatables

    @PostMapping(value = "guojini")
    public DataTablesOutput<LandMerchantGuoJin> list(@RequestBody @Valid DataTablesInput input) {
        return landMerchantGuojinRepository.findAll(input);
    }

angular-datatables

ngOnInit() {
    const that = this;
    this.titleService.setTitle(this.title);

    this.dtOptions = {
      serverSide: true,
      processing: true,
      ajax: (dataTablesParameters: any, callback) => {
        that.http
          .post<DataTablesResponse>(
            'http://localhost:8080/land/guojini',
            dataTablesParameters, {}
          ).subscribe(resp => {
            console.log(resp)
          that.data = resp.data;

          callback({
            recordsTotal: resp.recordsTotal,
            recordsFiltered: resp.recordsFiltered,
            data: []
          });
        });
      },
      columns: [{ data: 'id' }, { data: 'name' }, { data: 'shortName' }]
    };
  }