akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 878 forks source link

LocalDataSource vs ServerDataSource #461

Open shilan opened 7 years ago

shilan commented 7 years ago

I am not sure if I am getting this totally wrong or some minor thing is wrong with my code. But when I try Http and Promises with LocalDataSource I get this error: vendor.bundle.js:71464 ERROR Error: Uncaught (in promise): TypeError: this.data.slice is not a function TypeError: this.data.slice is not a function

at LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/local/local.data-source.js.LocalDataSource.getElements (vendor.bundle.js:24597) at LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/data-source.js.DataSource.emitOnChanged (vendor.bundle.js:24502) at LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/data-source.js.DataSource.load (vendor.bundle.js:24422) at LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/local/local.data-source.js.LocalDataSource.load (vendor.bundle.js:24560) at main.bundle.js:424 at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.bundle.js:5937) at Object.onInvoke (vendor.bundle.js:74334) at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.bundle.js:5936) at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (polyfills.bundle.js:5687)

But then it works with ServerDataSource. However I am not sure if I have understood the difference between these two entirely.

Here is my code in my Service: getData(): Promise<IBatchStatus[]> { return this._http.get(this._url) .toPromise() .then(response => response.json().data as IBatchStatus[]) .catch(this.handleError); }

and my component:

`@Component({
  selector: 'mifid-basic-example-load',
  template: `
    <ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
  `,
  styles: []
})
export class BasicExampleLoadComponent {
  source: LocalDataSource;

  settings = {
    actions: {
      add: false,
      edit: false,
      delete: false
    },
    columns: {...    },
    attr: {
      class: 'table-bordered table-striped'
    }
  };

  constructor(protected service: TheService) {
    this.source = new LocalDataSource();

    this.service.getData().then((data) => {
      this.source.load(data);
    });
  }
}`
jcjc712 commented 6 years ago

this could help you https://github.com/akveo/ng2-smart-table/issues/108