Php 按钮Datatable服务器端的返回值
伙计们,我怎样才能在我的专栏中添加一个按钮呢 PROTCLOASSUTO行动Php 按钮Datatable服务器端的返回值,php,mysqli,datatables,server-side,Php,Mysqli,Datatables,Server Side,伙计们,我怎样才能在我的专栏中添加一个按钮呢 PROTCLOASSUTO行动 001拉拉打印 Im使用datatable服务器端: <table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%"> <thead> <tr> <th>Protoco
001拉拉打印 Im使用datatable服务器端:
<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>Protocolo</th>
<th>Assunto</th>
<th>Action</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function() {
var otable = $('#datatable_fixed_column').DataTable({
"processing": true,
"serverSide": true,
"ajax": "server_processing/protocolos.php",
"order": [[ 0, "asc" ]],
"columnDefs": [
{ "width": "10%", "targets": 0 },
{ "width": "70%", "targets": 1 },
{ "width": "20%", "targets": 2 }
],
columns: [
{ data: "protocolo" },
{ data: "assunto" },
{
data: null,
defaultContent: '<form method="post" action=""><input type="hidden" id="idcontrib" name="idcontrib" value="id_protocolo"><button type="submit" class="btn btn-warning btn-xs" name="edit_contrib">Editar</button> <button type="submit" class="btn btn-danger btn-xs" name="exc_contrib">Excluir</button></form>'
}
],
"sDom": "<'dt-toolbar'<'col-xs-6'f><'col-xs-6'<'toolbar'>>r>"+
"t"+
"<'dt-toolbar-footer'<'col-xs-6'i><'col-xs-6'p>>"
});
$("div.toolbar").html('<div class="text-right"><img src="img/logo2.png" alt="SmartAdmin" style="width: 111px; margin-top: 3px; margin-right: 10px;"></div>');
})
</script>
第二
如何在隐藏字段中加载id_protocolo值?
<input type="hidden" id="idcontrib" name="idcontrib" value="id_protocolo">
您正在使用jQuery“DataTables”插件。事实上,jQuery和服务器代码看起来都是基于文档(www.datatables.net)中的示例代码
我要检查的第一件事是,jQuery是否正在与服务器通信。它甚至看到了“server\u processing/protocolo.php”吗
实现这一点的最佳方法是将代码缩减到最小行数——只是为了测试连接是否发生。在文档中,他们有如下JavaScript:
$(document).ready(function() { $('#example').dataTable( { "processing": true, "serverSide": true, "ajax": "scripts/server_processing.php" } ); } );
我将从这个开始,并尝试从服务器脚本返回“helloworld”。除非您知道任何类型的数据都是从服务器返回的,否则很难判断代码中可能存在哪些问题。
剧本
$(document).ready(function() {
var otable = $('#datatable_fixed_column').DataTable({
"processing": true,
"serverSide": true,
"ajax": "server_processing/contribuintes.php",
"order": [[ 2, "asc" ]],
"columnDefs": [
{ "width": "5%", "targets": 0 },
{ "width": "10%", "targets": 1 },
{ "width": "15%", "targets": 2 },
{ "width": "20%", "targets": 3 },
{ "width": "10%", "targets": 4 },
{ "width": "20%", "targets": 5 },
{ "width": "5%", "targets": 6 },
{ "render": actionlinks,
"data": null,
"targets": [7], "width": "15%", "targets": 7 },
],
});
function actionlinks(data, type, full) {
return '<form method="post" action=""><input type="hidden" id="idcontrib" name="idcontrib" value="' + full[0] + '"><button type="submit" class="btn btn-warning btn-xs" name="edit_contrib">Editar</button> <button type="submit" class="btn btn-danger btn-xs" name="exc_contrib">Excluir</button> <button type="submit" class="btn btn-info btn-xs" name="ativa_contrib">Reativar</button></form> ';
}
安德森·托雷斯
没有这个,它就可以工作<代码>列:[{data:“protocolo”},{data:“assunto”},{data:null,defaultContent:'Editar Excluir'}],但我需要在表中添加一个按钮。排他性编辑
<input type="hidden" id="idcontrib" name="idcontrib" value="id_protocolo">
$(document).ready(function() { $('#example').dataTable( { "processing": true, "serverSide": true, "ajax": "scripts/server_processing.php" } ); } );
$(document).ready(function() {
var otable = $('#datatable_fixed_column').DataTable({
"processing": true,
"serverSide": true,
"ajax": "server_processing/contribuintes.php",
"order": [[ 2, "asc" ]],
"columnDefs": [
{ "width": "5%", "targets": 0 },
{ "width": "10%", "targets": 1 },
{ "width": "15%", "targets": 2 },
{ "width": "20%", "targets": 3 },
{ "width": "10%", "targets": 4 },
{ "width": "20%", "targets": 5 },
{ "width": "5%", "targets": 6 },
{ "render": actionlinks,
"data": null,
"targets": [7], "width": "15%", "targets": 7 },
],
});
function actionlinks(data, type, full) {
return '<form method="post" action=""><input type="hidden" id="idcontrib" name="idcontrib" value="' + full[0] + '"><button type="submit" class="btn btn-warning btn-xs" name="edit_contrib">Editar</button> <button type="submit" class="btn btn-danger btn-xs" name="exc_contrib">Excluir</button> <button type="submit" class="btn btn-info btn-xs" name="ativa_contrib">Reativar</button></form> ';
}
<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>ID</th>
<th>CPF</th>
<th>Nome</th>
<th>Sobrenome</th>
<th>Celular</th>
<th>email</th>
<th>status</th>
<th>Ação</th>
</tr>
</thead>
</table>
$table = 'tbl_contribuintes';
$primaryKey = 'id_contrib';
$columns = array(
array( 'db' => 'id_contrib', 'dt' => 0 ),
array( 'db' => 'cpf', 'dt' => 1 ),
array( 'db' => 'fnome', 'dt' => 2 ),
array( 'db' => 'lnome', 'dt' => 3 ),
array( 'db' => 'celular1', 'dt' => 4 ),
array( 'db' => 'email', 'dt' => 5 ),
array( 'db' => 'id_status', 'dt' => 6 ),
);
$sql_details = array(
'user' => 'root',
'pass' => 'XXX',
'db' => 'XXX',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);