2

I am fetching data from an API and rendering it using Angular 2.

getData() {
        this.http.get('api/Employee').subscribe(result => {
            var localdata = result.json();
            for (var i = 0; i < localdata.length; i++)
                this.employeeList.push(localdata[i]);
            console.log(this.employeeList);   
            $('#example').DataTable();
        })
    }

Once I get the data I have to convert the normal table to Jquery Datatable using

$('#example').DataTable();

But I am facing below issue shows: No data available in table along with data.

enter image description here

2 Answers 2

1

I would suggest you to use angular-datatables

If that is not the case you can use array source like indicates here

$('#example').DataTable( {data: this.EmployeeList });

Also remember to destroy any existing datatable if you have already created one

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but there are some limitations for using angular-datatables. and very less documentation.
1

Finally solved this issue by importing AfterViewInit

export class EmployeeComponent implements AfterViewInit {   

    ngAfterViewInit() {
            setTimeout(() => {
                $('#example').DataTable();
            }, 1000);

        }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.