我有一个从CodeIgniter Controller生成的表:
public function ajax_list() {
$list = $this->InfoTable_model->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $resident) {
$no++;
$row = array();
// $row[] = '<td class="details-control"></td>';
$row[] = ''; // how do i insert class here where this will generate <td> element
$row[] = $resident->name;
$row[] = $resident->lname;
$row[] = $resident->gender;
$row[] = date('m/d/Y', strtotime($resident->bday));
$row[] = $resident->age;
$row[] = $resident->citizenship;
$row[] = $resident->occupation;
$row[] = $resident->status;
$row[] = $resident->purok;
$row[] = $resident->resAddress;
$row[] = $resident->perAddress;
$row[] = $resident->telNum;
$row[] = $resident->cpNum;
//add html for action
$row[] = '<a class="btn btn-sm btn-primary enable-tooltip" data-toggle="tooltip" href="javascript:void(0)" title="Edit Resident" onclick="edit_resident(' . "'" . $resident->resident_id . "'" . ')"><i class="fa fa-pencil"></i></a>
<a class="btn btn-sm btn-danger enable-tooltip" data-toggle="tooltip" href="javascript:void(0)" title="Delete Resident" onclick="delete_resident(' . "'" . $resident->resident_id . "'" . ')"><i class="fa fa-times"></i></a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->InfoTable_model->count_all(),
"recordsFiltered" => $this->InfoTable_model->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
我的 JS :
var tableData = $('#table').dataTable({
"oLanguage": {
"sProcessing": '<center><i class="fa fa-asterisk fa-2x fa-spin text-info"></i></center>'
},
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [
[1, 'asc']
], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": window.location.origin + "/InfoTable/ajax_list",
"type": "POST"
},
//Set column definition initialisation properties.
"columnDefs": [{
"targets": [-1, 0], //last column
"orderable": false //set not orderable
}],
"lengthMenu": [
[5, 10, 15, 20, 25],
[5, 10, 15, 20, 25]
]
});
php代码上方的row[] = '';
将生成<td>
元素。 我的问题是如何在其上插入属性的?我正在实现this从其父记录中执行成员列表,并在其中执行CRUD,如http://jtable.org/示例。
对上述问题的任何帮助,想法和其他建议都是天赐之别。