定制 datatables.net/editor-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

datatables.net/editor-php

Composer 安装命令:

composer require datatables.net/editor-php

包简介

PHP server-side libraries for DataTables

README 文档

README

This is a PHP library to provide easy server-side support for DataTables - the Javascript table library.

These libraries provide support for:

  • Server-side processing - work with millions of rows
  • Editor - CRUD UI for DataTables
  • ColumnControl - Column search controls for DataTables
  • SearchBuilder - Complex search logic UI

The library is framework-agnostic and can be used in any web framework, including Laravel, Symfony and CodeIgniter. It is dependency free, other than PHP core with PDO, and uses a database abstraction layer to operate with MySQL, Postgres, SQLite and SQLServer, using the same API.

Installation

Available on Packagist, this package can be installed with:

composer require datatables.net/editor-php

Then add:

require 'vendor/autoload.php'

to your files that use the DataTables classes. The required classes will be automatically included as you use them.

If you prefer not to use composer and include the PHP files directly, download them and require the DataTables.php file, which will load the auto loader for the classes:

require( $_SERVER['DOCUMENT_ROOT'] . 'lib/DataTables.php' );

Database connection

You must create a database connection using the Database class. This can be done automatically by defining the array $sql_details in config.php, or creating a new Database() class instance directly:

$db = new Database( [
	'type' => '',  // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite"
	'user' => '',  // Database user name
	'pass' => '',  // Database password
	'host' => '',  // Database host
	'port' => '',  // Database connection port (can be left empty for default)
	'db' => ''    // Database name
]);

There are two primary entry point classes in the library:

  • DataTable - for read only tables
  • Editor - for read / write tables, with Editor

There are also a number of supporting classes such as Options, Mjoin and more.

Quick Start

Once a database connection is configured, you can use the library to read and write data on a database - e.g. the following is a simple PHP file that acts as a CRUD end point for for a DataTables / Editor client-side:

<?php

// DataTables PHP library
include( "../lib/DataTables.php" );

// Alias the namespaces so the classes are easy to use
use
	DataTables\Editor,
	DataTables\Editor\Field,
	DataTables\Editor\Format,
	DataTables\Editor\Mjoin,
	DataTables\Editor\Options,
	DataTables\Editor\Upload,
	DataTables\Editor\Validate,
	DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from $_POST
new Editor( $db, 'datatables_demo' )
	->fields(
		new Field( 'first_name' )
			->validator( Validate::notEmpty( new ValidateOptions()
				->message( 'A first name is required' )	
			) ),
		new Field( 'last_name' )
			->validator( Validate::notEmpty( new ValidateOptions()
				->message( 'A last name is required' )	
			) ),
		new Field( 'position' ),
		new Field( 'email' )
			->validator( Validate::email( new ValidateOptions()
				->message( 'Please enter an e-mail address' )	
			) ),
		new Field( 'office' ),
		new Field( 'extn' ),
		new Field( 'age' )
			->validator( Validate::numeric() )
			->setFormatter( Format::ifEmpty(null) ),
		new Field( 'salary' )
			->validator( Validate::numeric() )
			->setFormatter( Format::ifEmpty(null) ),
		new Field( 'start_date' )
			->validator( Validate::dateFormat( 'Y-m-d' ) )
			->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
			->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
	)
	->process( $_POST )
	->json();

Note that the above uses PHP 8.4 syntax to chain a constructor without parentheses. If you are using an older version of PHP you can use either:

  • (new Editor($db, 'name'))->fields(...)
  • Editor:inst($db, 'name')->fields(...)

Similarly, if your table is readonly, the DataTable and Column classes can be used (this will support DataTables' client-side or server-side processing modes):

<?php

include( "../lib/DataTables.php" );

use
	DataTables\DataTable,
	DataTables\DataTable\Column;

new DataTable( $db, 'datatables_demo' )
	->columns(
		new Column( 'first_name' ),
		new Column( 'last_name' ),
		new Column( 'position' ),
		new Column( 'email' ),
		new Column( 'office' )
	)
	->process( $_POST )
	->json();

Documentation

For full documentation, please refer to the DataTables site.

License

MIT — see LICENSE for full text.

datatables.net/editor-php 适用场景与选型建议

datatables.net/editor-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 234.79k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2018 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「jquery」 「editor」 「datatables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 datatables.net/editor-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 datatables.net/editor-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 datatables.net/editor-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 36
  • Watchers: 8
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-05