philippfrenzel / yii2-dynatable
Yii2 dynatable 小部件
0.1.4
2016-09-30 07:09 UTC
Requires
- php: >=5.4.0
- bower-asset/dynatable: ~0.3.1
- yiisoft/yii2: *
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-18 18:13:23 UTC
README
JQuery Dynatable Yii2 扩展,JQuery 来自:http://dynatable.com
由 philipp@frenzel.net 开发的 Yii2 扩展
安装
尽管在 packagist.org 上注册了该包,但您只需添加一行代码即可运行!
将以下行添加到您的 composer.json 的 require 部分
"philippfrenzel/yii2-dynatable":"*",
并确保您已全局安装以下插件
php composer.phar global require "fxp/composer-asset-plugin:~1.0"
更新日志
29-11-2014 更新到库的最新 2.2.3 版本
使用方法
快速入门看起来像这样
<?= net\frenzel\dynatable\yii2dynatable::widget([
'id' => "nameofthetablethatwillbedynamised"
]);
表格模板
<table id="nameofthetablethatwillbedynamised">
<thead>
<tr>
<th data-dynatable-column="name">Name can contain anything now...</th>
<th>Hobby</th>
<th>Favorite Music</th>
</tr>
</thead>
<tbody>
<tr>
<td>Fred</td>
<td>Roller Skating</td>
<td>Disco</td>
</tr>
<tr>
<td>Helen</td>
<td>Rock Climbing</td>
<td>Alternative</td>
</tr>
<tr>
<td>Glen</td>
<td>Traveling</td>
<td>Classical</td>
</tr>
</tbody>
</table>
扩展选项包括
'clientOptions' => [
'table' => [
'defaultColumnIdStyle' => 'trimDash' //can be "underscore" too - look dynatable.js website for more options
],
'dataset' => [
'ajax' => true,
'ajaxUrl' => Url::to('/your/route/to/json'),
'ajaxOnLoad' => true,
'records' => [],
],
'features' => [
'paginate' => false,
'recordCount' => false,
'sorting' => true,
'search' => false
],
'params' => [
//'queries' => 'queries',
'sorts' => 'sort',
'page' => 'pageCount',
'perPage' => 'perPage',
'offset' => 'offset',
'records' => 'items',
'record' => 'item',
'queryRecordCount' => 'totalCount',
'totalRecordCount' => 'totalCount'
]
]
如果设置参数如上所示,dynatable 应该可以与内置的 yii2 rest api 正常工作。
如果您使用 Ajax,您需要确保响应看起来像这样
{ "records": [ { "someAttribute": "I am record one", "someOtherAttribute": "Fetched by AJAX" }, { "someAttribute": "I am record two", "someOtherAttribute": "Cuz it's awesome" }, { "someAttribute": "I am record three", "someOtherAttribute": "Yup, still AJAX" } ], "queryRecordCount": 3, "totalRecordCount": 3 }