Closed firazyn closed 3 years ago
Happy Lunar New Year.
In the TableIgniter, setOutput()
allows you to transmit arrays consists of the strings and anonymous function. If the array includings anonymous function, you should be aware of these three hints down below:
return
of the anonymous function must be a String
, because the TableIgniter will combine the results into the frontend DataTables.I made some changes to the codes you provided:
public function fetchProjectData()
{
$table = new TablesIgniter();
$table->setTable($this->projectModel->noticeTable())
->setDefaultOrder('project_name', 'ASC')
->setOrder([
'project_name', 'client_name', 'pm_name',
'start_date', 'finish_date', 'project_status', null
])
->setSearch(['project_name', 'client_name', 'pm_name', 'project_status'])
->setOutput([
'project_name', 'client_name', 'pm_name', 'start_date',
'finish_date', $this->projectStatus(), $this->projectModel->button()
]);
return $table->getDatatable();
}
public function projectStatus()
{
$closureFun = function ($row) {
// $row should belong to the query results.
if ($row['project_status'] == 'hold') {
return '<span class="badge rounded-pill bg-primary">Hold</span>';
} else {
return '<button type="button" class="btn btn-info">Detail</button>';
}
}
return $closureFun;
}
Issue solved. Thank you! I will close this thread.
Hi
public function projectStatus() { $closureFun = function ($row) { // $row should belong to the query results. if ($row['status'] == '1') { return 'Hold'; } else { return ''; } } return $closureFun; }
getting syntax error, unexpected token "return"
Thanks
Hello!
First thing to say is, thanks for this great library. It helped me a lot.
I tried to make the "Project Status" output with custom icons like this:
It can be done easily with a client-side, but I'm a bit confused on how to do it with the server-side (with your library, of course).
I tried with this code snippet, but it only returns a "Detail Button"
My goal is, the output can be the custom icons I've made, just like when I return a Button with the closure style. I'm still learning web development with CI4..
Thanks in advance.