Goal is to use webix.ui.datatable and Angular to pull data from server and display it.
My datatable component:
import { Component, Input, ElementRef, OnDestroy, OnInit, Output, EventEmitter } from '@angular/core';
import { Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment.test';
@Component({
selector: 'datatable',
template:""
})
export class DataTableComponent implements OnDestroy, OnInit {
private ui : webix.ui.datatable;
//private userData: any[] = [];
dtTrigger: Subject<any> = new Subject<any>();
constructor(private http: HttpClient, root: ElementRef) {
this.ui = <webix.ui.datatable>webix.ui({
container: root.nativeElement,
view: "datatable",
autoConfig: true,
autoheight: true,
/*url: function () {
let endpoint = "my_endpoint";
let headers = "my_headers";
let path = endpoint + '/test/path';
var promise = webix.ajax().headers(headers).get(path);
promise.then(function (data) {
let userData = data.json().data;
console.log(userData); //this is working -- an array of objects of format {col1: "data", col2: "data"}
return userData;
});
promise.catch(function (err) {
console.log('Failed to load data');
});
}*/,
data: [
{ id: 1, title: "The Shawshank Redemption", year: 1994, votes: 678790, rating: 9.2, rank: 1, category: "Thriller" },
{ id: 2, title: "The Godfather", year: 1972, votes: 511495, rating: 9.2, rank: 2, category: "Crime" },
{ id: 3, title: "The Godfather: Part II", year: 1974, votes: 319352, rating: 9.0, rank: 3, category: "Crime" },
{ id: 4, title: "The Good, the Bad and the Ugly", year: 1966, votes: 213030, rating: 8.9, rank: 4, category: "Western" },
{ id: 5, title: "Pulp fiction", year: 1994, votes: 533848, rating: 8.9, rank: 5, category: "Crime" },
{ id: 6, title: "12 Angry Men", year: 1957, votes: 164558, rating: 8.9, rank: 6, category: "Western" }
],
});
}
ngOnInit() {
this.ui.resize();
}
ngOnDestroy() {
this.ui.destructor();
}
}
I use datatable in parent.component.html as:
<rows type="space" class="pagebox">
<columns>
<cell><datatable class='pagebox'></datatable></cell>
</columns>
</rows>
As you can see, I have loaded static data via the data parameter in the constructor, which is displaying as expected.
But when I follow the documentation to load data through an AJAX call via the url parameter (commented out in the code above), the datatable does not display any data or column names. I can confirm that the data returned by the ajax call is an array of objects. Any input on how to solve this is appreciated.