Php 如何在具有子行(数据表)的子行中添加信息
我正在使用Datatables在一个表中加载信息,在这个表中,我想使用API在父行中加载一些信息,在子行中加载其他信息,以显示我使用AJAX的数据,如下所示:Php 如何在具有子行(数据表)的子行中添加信息,php,ajax,datatables,Php,Ajax,Datatables,我正在使用Datatables在一个表中加载信息,在这个表中,我想使用API在父行中加载一些信息,在子行中加载其他信息,以显示我使用AJAX的数据,如下所示: /* Formatting function for row details - modify as you need */ function format(d) { // `d` is the original data object for the row return '<table cellpadding=&
/* Formatting function for row details - modify as you need */
function format(d) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr>' +
'<td>Invoice Date</td>' +
'<td>' + d.InvoiceDate + '</td>' +
'</tr>' +
'</table>';
}
$(document).ready(function () {
var table = $('#example').dataTable( {
"ajax": {
"type": 'POST',
"url" : './utileria.php',
"dataType": 'JSON',
"cache": false,
"data": {
'param' : 1,
},
},
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data" : "PurchaseOrder" },
],
"order": [[1, 'asc']]
} )
// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
});
检查另一个相关问题@Jatniel您与我共享的链接是来自JSON文件的信息。在本例中,我使用的是对BDhi的查询,好的,我没有给您确切的答案,也许我可以帮助您。@Jatniel我已经查看了示例,如果它解决了我的问题,但我意识到它不适用于BDhi。请澄清(1)您面临的具体问题是什么,或者您可能在控制台中看到的具体错误是什么?(2)您的
格式(d)
函数中d
的内容是什么?
<?php
header('Content-Type: text/html; charset=utf-8');
$param = $_POST['param'];
switch($param) {
case '1': //Consulta
$query = array();
include './db/conectar.php';
$sql = "select PURCHID as 'PurchaseOrder',
INVOICEDATE as 'InvoiceDate'
FROM PP_FACTURAS F";
$stmt = sqlsrv_query($conn, $sql);
if ( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array($stmt) ) {
//print_r($row);
$record = array(
"PurchaseOrder" => $row['PurchaseOrder'],
"InvoiceDate" => $row['InvoiceDate']
);
array_push($query, $record);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
$json = array(
"success"=> count($query) > 0 ? true : false,
"data"=>$query
);
echo json_encode($json);
break;
}
?>
/* Formatting function for row details - modify as you need */
function format(d) {
// `d` is the original data object for the row
console.log(d);
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr>' +
'<td>Invoice Date</td>' +
'<td>' + d.InvoiceDate + '</td>' +
'</tr>' +
'</table>';
}