Guys. I'm reading json using datatable, but the users are not appearing in the table
Guys. I'm reading json using datatable, but the users are not appearing in the table
tadokatocom
Posts: 2Questions: 1Answers: 0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lista de Usuários</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
</head>
<body>
<div class="container mt-5">
<table class="table table-striped" id="userTable">
<thead>
<tr>
<th>Nome</th>
<th>Sobrenome</th>
<th>Email</th>
<th>Último login</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#userTable').DataTable({
paging: true,
pageLength: 20,
ajax: {
url: 'dados.json',
dataSrc: 'users',
},
columns: [
{ data: 'First Name [Required]' },
{ data: 'Last Name [Required]' },
{ data: 'Email Address [Required]' },
{
data: 'Last Sign In [READ ONLY]',
render: function (data) {
return data === "Never logged in" ? "Nunca fez login" : data;
}
}
]
});
});
</script>
</body>
</html>
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Guys. I'm reading json using datatable, but the users are not appearing in the table, could anyone help me?
The issue is probably that the data is a formatted that doesn't match the configuration. Can you post the results of
dados.json
, or link to your page that demonstrates the error.Colin