由 Codeigniter 支持的 jQuery DataTables

发布于 2024-10-17 04:31:51 字数 608 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-10-24 04:31:51

我已经在几个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文