samsonos9 / async_table9
异步渲染表格
dev-master
2016-08-10 15:19 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- knplabs/knp-paginator-bundle: ^2.4
- phpunit/phpunit: 5.5.*
This package is not auto-updated.
Last update: 2024-09-14 19:47:33 UTC
README
## 开始使用捆绑包
## 1. 添加配置文件config.yml
async_table:
views: ~
## 2. 创建查询并将其传递给创建表格服务
$query = $em->getRepository('...')->getQuery($request->query->get('filter'));
$tableData = [
['title' => 'Order ID', 'selector' => 'p.id', 'filter' => ['name' => 'order_id']],
['title' => 'Template ID', 'selector' => 't.id', 'filter' => [
'name' => 'template_id',
'type' => FilterMetadata::TYPE_SELECT,
'options' => [5, 6],
'empty_placeholder' => 'Select filter'
]],
['title' => 'Template Name'],
['title' => 'Status'],
['title' => 'Payment status'],
];
$table = $this->get('samsonos.async.table')->createTable('BackBundle:Handler/Order:table_content.html.twig', [
'query' => $query,
'page' => $request->query->get('page', 1)
], $tableData, [
'isCompanyGroup' => $this->get('manager.domain')->isCompanyGroupMode()
]
);
Where BackBundle:Handler/Order:table_content.html.twig - is table content
% for entity in pagination %}
<tr data-user-id="{{ entity.id }}">
{% set doc = entity.document.toArray() %}
<td><span class="wrap-td" title="{{ entity.id }}">{{ entity.id }}</span></td>
<td><span class="wrap-td" title="{{ entity.template.id }}">{{ entity.template.id }}</span></td>
<td><span class="wrap-td" title="{{ doc[0].name }}">{{ doc[0].name }}</span></td>
<td><span class="wrap-td" title="{{ entity.textStatus }}">{{ entity.textStatus }}</span></td>
<td>...
## 3. 您可以通过捆绑包js处理请求
if (null !== ($response = $this->get('samsonos.async.table')->handleContent($request, $table))) {
return $response;
}
## 4. 简单渲染视图
return $this->render('BackBundle:Handler/Order:list.html.twig', [
'table' => $table,
]);
## 5. 在twig模板中使用async_table进行表格渲染
{{ async_table(table) }}
## 6. 不要忘记包含js脚本
'@AsyncTableBundle/Resources/public/js/async-table.js'
快乐:)