由 Codeigniter 支持的 jQuery DataTables
我使用 jQuery DataTables 和 DataTables Codeigniter 库来生成数据。该库是 DataTables 提供的 php 脚本的端口。
该脚本仅允许我确定几个选项。
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);
}
我希望能够为某些“行特定”功能(如编辑和删除)添加列,但 DataTable 库不支持提供经过处理的数据数组。
看来我的下一个选择是一些 jQuery。我想我需要一个隐藏列来存储该行的唯一 id,然后为该行特定函数添加一列。这看起来对吗?
任何其他建议或更好的方法将很高兴听到。
谢谢, 彼得
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 unique 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经在几个 CI 项目中使用了 DataTables,但没有采用与您相同的方法 - 我没有使用任何类型的包装器库,而是通过 jQuery 传递选项。我认为有时这种方法更好,因为如果 CI 库中间层不提供 javascript 库的完整选项,它可能会妨碍。
您可以通过多种方式提供行特定功能 - 具有编辑列或删除列,并带有指向该行的控制器方法的链接(例如“/mycontroller/edit/123”);或者有一个复选框列,其中包含每个 ID 的值和“操作”按钮或表单选择。
根据数据的大小,我通常利用 DataTables 的 ajax 功能并通过 json 加载列数据 - 如果您在数据中包含 html 和/或 javascript,只需确保正确转义即可。
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.