I'm trying to do something like this https://datatables.net/blog/2012-05-31 However, I'm also using Server Side Processing.
My problem is at the adding new rows section.
Here is my example that doesn't work:
var t = $("#table").DataTable({
"ajax": "https://api.myjson.com/bins/2k6e5",
"serverSide": true,
"autoWidth": false,
"responsive": true,
"ordering": true,
"searching": true,
"paging": true,
"columns": [{
data: "Id"
}, {
data: "Name"
}, {
data: "Actived"
}]
});
var model = [{
"Id": 4,
"Name": "Name of the Object",
"Actived": true
}];
console.log(model);
t.rows.add(model).draw();
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js"></script>
<table id="table" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actived</th>
</tr>
</thead>
<tbody></tbody>
</table>
Here is my example that does work:
var t = $("#tableRegistros").DataTable({
"ajax": "https://api.myjson.com/bins/2k6e5",
//"serverSide": true,
"autoWidth": false,
"responsive": true,
"ordering": true,
"searching": true,
"paging": true,
"columns": [{
data: "Id"
}, {
data: "Name"
}, {
data: "Actived"
}]
});
var model = [{
"Id": 4,
"Name": "Name of the Object",
"Actived": true
}];
console.log(model);
t.rows.add(model);
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js"></script>
<table id="tableRegistros" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actived</th>
</tr>
</thead>
<tbody></tbody>
</table>
The only difference is the serverSide option.