fgsl / eyedatagrid
在可排序的表格中显示数据库中的数据
Requires
- php: ^5.6 || ^7.0
This package is auto-updated.
Last update: 2024-09-10 00:48:36 UTC
README
基于Mike Frank创建的类版本1.0 mike@eyesis.ca http://www.eyesis.ca 原始源代码: https://www.phpclasses.org/package/4951-PHP-Display-data-from-a-database-in-a-sortable-table.html
由于前EyeDataGrid自2008年以来没有更新,并且在当前的PHP环境中存在致命错误,因此构建了此组件。
关于
此类可用于在可排序的HTML表中显示SQL数据库中的数据。它可以执行给定的SQL查询并生成HTML和JavaScript来在HTML表中显示数据。可以通过单击列标题标题对表列表进行排序。数据网格表还可以使用Ajax显示。其创作者Mike对现有的PHP数据网格控件不满意。他在他开发的每个网站上使用数据网格。据他所说,它们非常适合显示各种类型的数据。他认为开发自己的数据网格是为了满足他的所有需求以及更多。
特性
- 过滤和搜索功能
- 可以更改列标题
- 能够显示图像
- 自动行分页
- 行选择
- 支持MySQL数据库
- 隐藏列
- 排序列
- 通过CSS自定义外观和感觉
- 可以处理大量数据集
- 可以添加控件
- 复选框支持
- 指定列格式类型(如百分比、美元等)
- 更多...
文件
Eyedatagrid.php
主要的datagrid类
EyeMySQLAdap..php
Mike在以前的项目中创建的Mysql包装类 - 通过使用另一个类进行改进
ex.php* -示例datagrid
从local.inc.php模板在config文件夹中创建一个名为local.php的文件,并用数据库访问参数填充。
ex.png*
示例的图像
sample data.sql
用于玩耍的示例数据(来自示例)。
从这个脚本创建一个数据库以运行示例。
table.css
-The style layout for the datagrid table
占位符变量
在datagrid控件中什么是占位符?
- 占位符与变量相同。它是一个名称,并引用特定行的列。
- 例如,假设您有一个包含PetName、PetAge和PetComment列的Pet表。
- 您可以通过将百分号(%)放在指定的列名周围来引用PetComment中的其他列。
- 如果在setQuery方法中设置了主键,您可以使用%_P%作为表的唯一键的占位符。在哪里可以使用这个?
- 这可以在数据库或脚本中。
- 这可以在列类型标准中以及criteria_2参数中使用。在TYPE_IMAGE和TYPE_CUSTOM下查看更多示例。
列类型和用法
对可用列类型的快速概述。
TYPE_ONCLICK
在单元格值上设置"onclick"调用。
例如
$db->setColumnType('FirstName', EyeDataGrid::TYPE_ONCLICK, "alert('Hello?')");
TYPE_HREF
在单元格值上设置href链接。
例如
$db->setColumnType('FirstName', EyeDataGrid::TYPE_HREF, "http://www.google.com");
TYPE_DATE
格式化日期。
例如
$db->setColumnType('Birthday', EyeDataGrid::TYPE_DATE, "M d, Y", true); // Converts to a timestamp and then to the formatted date $db->setColumnType('Birthday', EyeDataGrid::TYPE_DATE, "M d, Y"); // Converts formatted date from a timestamp
TYPE_IMAGE
将列值更改为图像。
例如
$db->setColumnType('Photo', EyeDataGrid::TYPE_IMAGE, "/images/photos/%LastName%.png");
TYPE_ARRAY
将值映射到数组中的键
$db->setColumnType('Gender', EyeDataGrid::TYPE_ARRAY, array('f' => 'Female', 'm' => 'Male'));
TYPE_CHECK
当值为 "1"、"true"、"yes" 或与第三个传入的值匹配时,将单元格转换为勾选标记。
例如
$db->setColumnType('Single?', EyeDataGrid::TYPE_CHECK); $db->setColumnType('Single?', EyeDataGrid::TYPE_CHECK, 'legs');
TYPE_PERCENT
将值转换为整数百分比。
例如
$db->setColumnType('Score', EyeDataGrid::TYPE_PERCENT); // Value is already in percent $db->setColumnType('Score', EyeDataGrid::TYPE_PERCENT, true); // Value is converted from decimal format when 3rd param is true $db->setColumnType('Score', EyeDataGrid::TYPE_PERCENT, true, array('Back' => 'red', 'Fore' => 'black')); // Adds bars whose width represents the percent, colors are specified as 'Back' and 'Fore'
TYPE_DOLLAR
将值转换为货币。始终四舍五入到两位小数。
例如
$db->setColumnType('Price', EyeDataGrid::TYPE_DOLLAR);`
TYPE_CUSTOM
将值转换为自定义值。
例如
$db->setColumnType('School', EyeDataGrid::TYPE_CUSTOM, 'I go to %CollegeName% in %City%, %Province%'); // Converts a cell to "I go to..". Placeholders are replaced with the value in that row's column
TYPE_FUNCTION
将值(或值)发送到用户指定的函数。
例如
$db->setColumnType('Password', EyeDataGrid::TYPE_FUNCTION, 'md5', '%Password%'); // Value is sent to the md5 function and return is printed in the cell $db->setColumnType('Password', EyeDataGrid::TYPE_FUNCTION, 'make_hash', '%Password%'); // Value is sent to the make_hash user function and return is printed in the cell $db->setColumnType('Password', EyeDataGrid::TYPE_FUNCTION, 'generate_key', array('%Username%', '%Password%')); // To pass multiple params to the user function use an array