我正在尝试实现类似于https://datatables.net/blog/2012-05-31的功能,但是我也在使用服务器端处理。
我的问题出现在添加新行部分。
这是我的示例,它无法正常工作:
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>
这是一个有效的示例:
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>
问题:如何在服务器端处理时使用 row.add()?