简介:我正在使用json,ajax和ssp.class.php做一个服务器端 datatable.net Jquery插件。我让它工作,但试图制作可以编辑和删除的按钮。我可以在没有插件的情况下做到这一点(但由于某种原因目前被难住了(。
法典:
$(document).ready(function() {
$('#example').DataTable( {
// "pagingType": "scrolling",
"processing": true,
"serverSide": true,
"ajax": {
"url": "server.php",
"type": "POST"
},
});
});
</script>
<body>
<table id="example" class="display" style="width:100%" class="table table-striped table-bordered table-hover table-condensed">
<thead class="thead-inverse">
<tr>
<th><a class="column_sort" id="id" href="?order=id&sort=<?php echo $sort; ?>">
ID
</th>
<th><a class="column_sort" id="first_name" data-order="<?php echo $sort;?>" href="?order=first_name&sort=<?php echo $sort; ?>">First Name </a>
</th>
<th><a class="column_sort" id="last_name" href="?order=last_name&sort=<?php echo $sort; ?>">Last Name
</a>
</th>
<th><a class="column_sort" id="position" href="?order=position&sort=<?php echo $sort; ?>">Position
</a>
</th>
<th class="hidden-xs"><a class="column_sort" id="date" href="?order=date&sort=<?php echo $sort; ?>">Date </a>
</th>
<th class="hidden-xs"><a class="column_sort" id="updated" href="?order=updated&sort=<?php echo $sort; ?>">Updated
</a> </th>
<th>Action</th>
</thead> </tr>
<tbody>
</tbody>
</table>
</div>
<?php
$orderby="";
$sort="";
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'ASC';
$sort = ($sort == 'ASC') ? 'DESC': 'ASC';
$order = array("first_name","last_name", "date", "position", "updated");
$key = array_search($sort, $order);
$orderby = $order[$key];
$records = mysqli_query($con, "SELECT * FROM employees ORDER BY $orderby $sort");
$data=array();
while ($row = mysqli_fetch_array($records, MYSQLI_ASSOC)) {
$row['delete_button']='<button type="button" class="btn btn-warning">Delete</button>';
$data[]=$row;
}
$requestData= $_REQUEST;
$count=mysqli_query($con, "SELECT * FROM employees");
$totalData= $count->num_rows;
$totalFiltered=$totalData;
$json_data = array(
"draw" => intval(isset($_GET['draw'])),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data //How To Retrieve This Data
);
echo json_encode($json_data);
?>
错误:数据表警告:表 id=example - 第 0 行第 6 列的请求未知参数"6"。有关此错误的详细信息,请参阅 http://datatables.net/tn/4
已经有一个类似的话题,似乎没有人有任何线索。任何帮助将不胜感激。提前谢谢。
这是解决方案。我不得不使用columnDef:
$(document).ready(function() {
var asc = true;
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "server.php",
"type": "POST"
},
columnDefs: [{
"searchable": true
targets: -1,
defaultContent: '<button type="button">Delete</button>'
}],
});
});