jQuery DataTables fueled by Codeigniter
Im using jQuery DataTables with a DataTables Codeigniter Library for generating data. This library is a port of the php script provided by DataTables.
The script allows me to only determine a few options.
function datatables()
{
$table = "purchase_orders";
$columns = array("purchase_order_id", "sequence_id", "order_number", "aid");
$index = "purchase_order_id";
$this->load->library("Datatables");
echo $this->datatables->generate($table, $columns, $index);
}
I would like to be able to add a column for some "row specific" functions like edit
and delete
, but DataTable Library does not support being provided a massaged array of data.
It seems like my next option would be some jQuery. I figure I will need to have one hidden column that stores a uniq开发者_如何学运维ue id about the row, then add a column for the row specific functions. Does that seem right?
Any other suggestions or better approaches would be great to hear.
Thanks, Peter
I have used DataTables for several CI projects, but did not take the same approach as you - I haven't used any kind of wrapper library, and instead pass options via jQuery. I think sometimes this approach is better, as the CI library middle layer can get in the way if it does not provide the full options of the javascript library.
You can provide row specific functions in many ways - have an edit column or delete column, with a link to your controller method for this row (e.g. '/mycontroller/edit/123'); or have a checkbox column with the value of each of your ids and "action" buttons or a form select.
Depending on the size of the data, I typically utilise the ajax functionality of DataTables and load the column data via json - if you're including html and / or javascript in your data, just be sure to escape it correctly.
精彩评论