xxxxxxxxxx
1
<div id="datatable" data-mdb-loading="true"></div>
1
1
xxxxxxxxxx
1
const columns = [
2
{ label: 'Address', field: 'address' },
3
{ label: 'Company', field: 'company' },
4
{ label: 'Email', field: 'email' },
5
{ label: 'Name', field: 'name' },
6
{ label: 'Phone', field: 'phone' },
7
{ label: 'Username', field: 'username' },
8
{ label: 'Website', field: 'website' },
9
];
10
11
const asyncTable = new mdb.Datatable(
12
document.getElementById('datatable'),
13
{ columns, },
14
{ loading: true }
15
);
16
17
fetch('https://jsonplaceholder.typicode.com/users')
18
.then((response) => response.json())
19
.then((data) => {
20
asyncTable.update(
21
{
22
rows: data.map((user) => ({
23
...user,
24
address: `${user.address.city}, ${user.address.street}`,
25
company: user.company.name,
26
})),
27
},
28
{ loading: false, entriesOptions: [2, 10, 25] }
29
);
30
});
Console errors: 0