这是我的问题,我目前正在为 prestashop 开发一个模块, 我正在使用两个网格组件来渲染网格数据 我插入了为我的模块创建的表格。
我使用的是 Prestashop 1.7.8.9 ,以及文档提供的默认实现, 我创建了自己的定义和查询构建器,以便按照文档的说明与数据工厂和网格工厂一起使用。
网格显示没有任何问题,但是当我使用分页链接时它不起作用。
单击链接时,偏移值是准确的。 可能是什么问题导致了这个问题?谢谢你。
我尝试让我的分页正常工作,但没有成功。
这是我的代码:
<?php
namespace PrestaShop\Module\Stabs\Tables;
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
class GridCategoryExtrafields extends AbstractGridDefinitionFactory
{
protected function getId()
{
return 'extrafields' ;
}
protected function getName()
{
return $this->trans('Category Features',[],'Admin.Advparameters.Feature') ;
}
protected function getColumns()
{
//id id_category label_extrafield is_excluded is_visible
return(new ColumnCollection())
->add((new DataColumn('id'))
->setName($this->trans('ID',[],'Admin.Global'))
->setOptions([
'field'=> 'id'
])
)->add((new DataColumn('id_category'))
->setName($this->trans('ID catégorie',[],'Admin.Advparameters.Feature'))
->setOptions([
'field' => 'id_category'
])
)->add((new DataColumn('label_extrafield'))
->setName($this->trans('Label extrafield',[],'Admin.Advparameters.Feature'))
->setOptions([
'field'=> 'label_extrafield'
])
)->add((new DataColumn('is_excluded'))
->setName($this->trans('Exclu des imports',[],'Admin.Advparameters.Feature'))
->setOptions([
'field'=> 'is_excluded'
])
)->add((new DataColumn('is_visible'))
->setName($this->trans('Traité différement',[],'Admin.Advparameters.Feature'))
->setOptions([
'field'=> 'is_visible'
]));
}
}
<?php
namespace Prestashop\Module\Stabs\Tables;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder;
final class GridCategoryExtrafieldsQueryBuilder extends AbstractDoctrineQueryBuilder
{
private $contextLangId;
private $contextShopId;
public function __construct(Connection $connection, $dbPrefix, $contextLangId, $contextShopId )
{
parent::__construct($connection, $dbPrefix);
$this->contextLangId = $contextLangId;
$this->contextShopId = $contextShopId;
}
public function getSearchQueryBuilder(\PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface $searchCriteria)
{
$qb = $this->getBaseQuery();
$qb->orderBy(
$searchCriteria->getOrderBy(),
$searchCriteria->getOrderWay()
)
->setFirstResult($searchCriteria->getOffset())
->setMaxResults($searchCriteria->getLimit());
foreach ($searchCriteria->getFilters() as $filtername => $filtervalue) {
if ('id' == $filtername) {
$qb->andWhere("id = :$filtername");
$qb->setParameter($filtername, $filtervalue);
continue;
}
$qb->andWhere("$filtername LIKE :$filtername");
$qb->setParameter($filtername, '%' . $filtervalue . '%');
}
return $qb;
}
public function getCountQueryBuilder(\PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface $searchCriteria)
{
$qb = $this->getBaseQuery();
$qb->select('COUNT(id)');
return $qb;
}
public function getBaseQuery()
{
return $this->connection
->createQueryBuilder()
->from($this->dbPrefix . 'category_extrafield')
->select('id, id_category, label_extrafield, is_excluded, is_visible');
}
}
prestashop.module.stabs.tables.grid_visible_table:
class: 'PrestaShop\Module\Stabs\Tables\GridVisibleTable'
parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
public: true
prestashop.module.stabs.tables.visible_query_builder:
class: 'PrestaShop\Module\Stabs\Tables\VisibleQueryBuilder'
parent: 'prestashop.core.grid.abstract_query_builder'
arguments:
- "@=service('prestashop.adapter.legacy.context').getContext().language.id"
- "@=service('prestashop.adapter.legacy.context').getContext().shop.id"
public: true
prestashop.module.stabs.visible_data_factory:
class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\DoctrineGridDataFactory'
arguments:
- '@prestashop.module.stabs.tables.visible_query_builder'
- '@prestashop.core.hook.dispatcher'
- '@prestashop.core.grid.query.doctrine_query_parser'
- 'visible'
prestashop.core.grid.visible_grid_factory:
class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
arguments:
- '@prestashop.module.stabs.tables.grid_visible_table'
- '@prestashop.module.stabs.visible_data_factory'
- '@prestashop.core.grid.filter.form_factory'
- '@prestashop.core.hook.dispatcher'
prestashop.module.stabs.tables.grid_category_extrafield_table:
class: 'PrestaShop\Module\Stabs\Tables\GridCategoryExtrafields'
parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
public: true
prestashop.module.stabs.tables.grid_category_extrafield_query_builder:
class: 'PrestaShop\Module\Stabs\Tables\GridCategoryExtrafieldsQueryBuilder'
parent: 'prestashop.core.grid.abstract_query_builder'
arguments:
- "@=service('prestashop.adapter.legacy.context').getContext().language.id"
- "@=service('prestashop.adapter.legacy.context').getContext().shop.id"
public: true
prestashop.module.stabs.grid_category_extrafield_data_factory:
class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\DoctrineGridDataFactory'
arguments:
- '@prestashop.module.stabs.tables.grid_category_extrafield_query_builder'
- '@prestashop.core.hook.dispatcher'
- '@prestashop.core.grid.query.doctrine_query_parser'
- 'extrafields'
prestashop.core.grid.grid_category_extrafield_factory:
class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
arguments:
- '@prestashop.module.stabs.tables.grid_category_extrafield_table'
- '@prestashop.module.stabs.grid_category_extrafield_data_factory'
- '@prestashop.core.grid.filter.form_factory'
- '@prestashop.core.hook.dispatcher'
$SearchCriteria = new SearchCriteria([], 'id_product', 'DESC', 1, 10);
$gridfactory = $this->get('prestashop.core.grid.visible_grid_factory');
$visiblegrid = $gridfactory->getGrid($SearchCriteria);
$SearchCriteriaExtrafields = new SearchCriteria([], 'id', 'ASC', null, 10);
$gridextrafieldfactory = $this->get('prestashop.core.grid.grid_category_extrafield_factory');
$extrafieldgrid = $gridextrafieldfactory->getGrid($SearchCriteriaExtrafields);
return $this->render('@Modules/stabs/views/templates/admin/form.html.twig',[
'formtitle' => $formname,
'form' => $form->createView(),
'extragrid' => $this->presentGrid($extrafieldgrid),
'grid' => $this->presentGrid($visiblegrid),
]);
网格与表单同时呈现。 这是我使用的文档:https://devdocs.prestashop-project.org/1.7/development/components/grid/
我也有同样的问题。你能同时解决吗?
我还在模板中添加了pagination.js,但仍然没有变化...