承接 glazilla/datatable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

glazilla/datatable

最新稳定版本:1.3.1

Composer 安装命令:

composer create-project glazilla/datatable

包简介

Class generating JSON output form mysql/pdo pgsql/pdo usable for Javascript library DataTables

README 文档

README

Packagist

Glazilla\DataTable is a PHP class to simplify server-side integration of jQuery DataTables with MariaDB and PostgreSQL, with advanced features: filtering, ordering, pagination and ES6 compatibility.

Installation

composer require glazilla/datatable

Usage

Create PDO Connection

$pdo = new PDO('mysql:host=127.0.0.1;dbname=testdb', 'test', 'test'); // MariaDB
$pdo = new PDO('pgsql:host=127.0.0.1;dbname=testdb', 'test', 'test'); // PostgreSQL

If you wan't to search using UNACCENT postgreSQL extension, activate the extension and insert this constant in your code :

define("UNACCENT_QUERY_PG", "1");

PHP

use Glazilla\DataTable\DataTable;

$dt = new DataTable($pdo);
echo $dt->query(['name', 'email'], 'id', 'users', '1=1', [], 2);

Or for PostgreSQL:

echo $dt->queryPG(['name', 'email'], 'id', 'users', '1=1', [], 2);

JavaScript

<table id="myTable"><thead><tr><th>Name</th><th>Email</th></tr></thead></table>
<script>
$('#myTable').DataTable({
  serverSide: true,
  ajax: '/data.php',
  columns: [{ data: 0 }, { data: 1 }]
});
</script>

Docker demo

Run:

docker compose up -d

Open http://localhost:8080

History

  • 2025-08-21 - Reverted filtering logic for both queryPG and query methods : column-specific filters are now applied ONLY if the global search is empty. This restores the behavior where global search takes precedence.
  • 2025-07-08 - Added support for the ES6 dataTables.mjs format (by default, the old format remains in place): the new $retourFormat parameter allows you to choose the return format (1: old, 2: ES6)
  • 2025-06-11 - Fixed bug in postgresql filter
  • 2025-03-31 - Modified QueryPG to use PreparedStatement
  • 2024-02-08 - UNACCENT evaluated as constant or env var
  • 2023-12-21 - Add constant to search with PostgreSQL using UNACCENT PG extension (has to be initialized prior tu use) : Use define("UNACCENT_QUERY_PG", "1");
  • 2022-12-04 - Add possibility to combine searches with | (or) in input fields
  • 2022-03-03 - Fixed typo
  • 2021-10-16 - Fixed search on numeric types
  • Use QueryPG for PosgreSQL
  • Use Query for MySQL / MariaDB

License

MIT

统计信息

  • 总下载量: 3.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-15