Я получаю информацию об одном объекте и хочу отобразить его в таблице.Я использую DataTable для этого, до сих пор я выбрал единый объект JSON, как показано ниже:
$CxRecordsTable.delegate('form', 'submit', function(event) {
event.preventDefault();
var $form = $(this);
var quizId = $form.attr('id');
$.post('<?php echo $this->CxHelper->Route('eb-admin-get-evaluation-quiz-by-id')?>', {
id: quizId
}).done(function(data, textStatus, jqXHR){
quizDetail = jqXHR.responseText;
});
Теперь я хочу quizDetail
, который является единственной строкой JSON объекта, чтобы показать ее в dataTable.Проще говоря, я хочу, чтобы эта сущность отображалась в DataTable, то, что я попробовал, приведено ниже:
var jsonString = JSON.stringify(quizDetail) //for testing
//Load datatable
var table = $("#cx-evaluation-quiz-details-table");
table.DataTable ({
data : jsonString,
"columns" : [
{ "first_name" : "first_name" },
{ "gender" : "gender" },
{ "email" : "email" },
{ "phone" : "phone" },
{ "age" : "age" },
{ "version" : "version" },
{ "date" : "date" }
]}
);
МОЙ HTML-код таблицы:
<table id="cx-evaluation-quiz-details-table" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th></th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="First Name">
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Gender" />
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Email" />
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Phone" />
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Age" />
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Version" />
</th>
<th class="hasinput">
<input type="text" class="form-control filter" placeholder="Date" />
</th>
</tr>
<tr>
<th></th>
<th class="all">First Name</th>
<th class="all">Gender</th>
<th class="all">Email</th>
<th class="all">Phone</th>
<th class="all">Age</th>
<th class="all">Version</th>
<th class="all">Date</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Код BackQend GetQuizBYId:
public function getEvaluationQuizByIdAction() {
// Get the clicked evaluation quiz id
$id = $this->request->get('id', null);
// Return Evaluation Quiz record
$cxEbEvaluation = CxEbEvaluation::getEvaluationByIdForDataTable($id);
// Return data array
return array('data' => $cxEbEvaluation);
}