raliable/ci4-datatables
Composer 安装命令:
composer require raliable/ci4-datatables
包简介
A DataTables library for CodeIgniter 4
README 文档
README
This library provides a simple and efficient way to implement server-side processing for DataTables in CodeIgniter 4 applications.
Installation
You can install this library via Composer. Run the following command in your project directory:
composer require raliable/ci4-datatables
Usage
1. Load the Library
In your controller, load the DataTables library and configure it as needed:
<?php namespace App\Controllers; use \Raliable\DataTables\DataTables; use CodeIgniter\API\ResponseTrait; class DataTableController extends BaseController { use ResponseTrait; public function index() { return view('datatable_view'); } public function ajax_list() { $config = [ 'table' => 'your_table_name', ]; $datatables = new DataTables($config); $datatables->select('id, name, address, email') ->join('another_table', 'another_table.foreign_key = your_table_name.id', 'left') ->where('status', 1) ->orderBy('id', 'asc'); return $datatables->generate(); } }
2. Configure Your View
Create a view file (e.g., datatable_view.php) to display the DataTable:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>DataTables Example</title> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function() { $('#example').DataTable({ "processing": true, "serverSide": true, "ajax": { "url": "<?= base_url('datatablecontroller/ajax_list') ?>", "type": "POST", "data": function (d) { d.<?= csrf_token() ?> = "<?= csrf_hash() ?>"; } }, "columns": [ { "data": "id", "bSortable": false, "searchable": false }, { "data": "name", "bSortable": true, "searchable": true }, { "data": "address", "bSortable": false, "searchable": true }, { "data": "email", "bSortable": true, "searchable": true } ] }); }); </script> </head> <body> <table id="example" class="display" style="width:100%"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Address</th> <th>Email</th> </tr> </thead> </table> </body> </html>
Methods
select(string $columns): Select the columns to be returned.join(string $table, string $fk, string $type = null): Join another table.where(string $keyCondition, $val = null): Add awhereclause.orWhere(string $keyCondition, $val = null): Add anorWhereclause.whereIn(string $keyCondition, array $val = []): Add awhereInclause.orderBy($column, string $order = 'ASC'): Add anorderByclause.groupBy(string $groupBy): Add agroupByclause.generate(bool $raw = false): Generate the DataTables response. Ifrawistrue, returns an array, otherwise returns a JSON response.
raliable/ci4-datatables 适用场景与选型建议
raliable/ci4-datatables 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 raliable/ci4-datatables 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 raliable/ci4-datatables 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 73
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-15