Jump to content

Search not working on Grid Data custom module


Recommended Posts

Hello  , 

I have a custom module with an adminController , i have tried documentation tutorial to create a data grid system  for my entity.
The Grid shows well but search action is not working.

ps_custom_catgeoires_articles.yml 
 

services:
  #ObjectModel service
  prestashop.module.ps_custom.entity.ps_custom_categories_articles:
    class: \PrestaShop\Module\PsCustom\Entity\PsCustomCategoriesQuestionsAnswer

  #Grid Factory
  prestashop.module.ps_custom.grid.factory.table.ps_custom_categories_articles:
    class: PrestaShop\PrestaShop\Core\Grid\GridFactory
    arguments:
      - "@prestashop.module.ps_custom.grid.definition.table.ps_custom_categories_articles"
      - "@prestashop.module.ps_custom.grid.data.factory.table.ps_custom_categories_articles"
      - "@prestashop.core.grid.filter.form_factory"
      - "@prestashop.core.hook.dispatcher"

  #Grid definition
  prestashop.module.ps_custom.grid.definition.table.ps_custom_categories_articles:
    class: PrestaShop\Module\CpmCore\Grid\BaseGridDefinition
    parent: "prestashop.core.grid.definition.factory.abstract_grid_definition"
    public: true
    arguments:
      $gridId: "ps_custom_categories_articles"
      $gridName: "ps_custom_categories_articles"
      $gridFields: "@=service('prestashop.module.ps_custom.entity.ps_custom_categories_articles').getFields()"
      $searchAndResultRedirectRoute: "admin.ps_custom.table.ps_custom_categories_articles.index"

  #Grid Factory Decorator
  prestashop.module.ps_custom.grid.data.factory.table.ps_custom_categories_articles:
    class: PrestaShop\Module\CpmCore\Grid\BaseGridDataFactory
    arguments:
      - "@prestashop.module.ps_custom.grid.data_provider.table.ps_custom_categories_articles"

  #Grid Data Provider
  prestashop.module.ps_custom.grid.data_provider.table.ps_custom_categories_articles:
    class: "%prestashop.core.grid.data.factory.doctrine_grid_data_factory%"
    arguments:
      - "@prestashop.module.ps_custom.grid.query.table.ps_custom_categories_articles"
      - "@prestashop.core.hook.dispatcher"
      - "@prestashop.core.grid.query.doctrine_query_parser"
      - "ps_custom_categories_articles"

  # Grid data query builder
  prestashop.module.ps_custom.grid.query.table.ps_custom_categories_articles:
    class: PrestaShop\Module\CpmCore\Grid\BaseGridQueryBuilder
    arguments:
      $connection: "@doctrine.dbal.default_connection"
      $dbPrefix: "%database_prefix%"
      $tableName: "ps_custom_categories_articles"
      $counterColumn: "id_ps_custom_categories_articles"

  #Grid filters
  prestashop.module.ps_custom.grid.filter.table.ps_custom_categories_articles:
    class: PrestaShop\Module\CpmCore\Grid\BaseGridFilter
    arguments:
      $filterId: "ps_custom_categories_articles"
      $defaultOrderBy: "id_ps_custom_categories_articles"
      $defaultSortOrder: "desc"

 


Admin Controller : 

 

 

<?php

namespace PrestaShop\Module\PsCustom\Controller\Admin\Table;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
use PrestaShopBundle\Security\Annotation\ModuleActivated;
use PrestaShopBundle\Service\Grid\ResponseBuilder;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class PsCustomModuleCategoriesArticlesController.
 *
 * @ModuleActivated(moduleName="PsCustomModule", redirectRoute="admin_module_manage")
 */
class PsCustomModuleCategoriesArticlesController extends FrameworkBundleAdminController
{
    /**
     * @see https://devdocs.prestashop.com/1.7/development/architecture/migration-guide/controller-routing/#security
     * @AdminSecurity(
     *     "is_granted(['read'], request.get('_legacy_controller'))",
     *     message="You do not have permission to access PsCustomModule tables page."
     * )
     */
    public function indexAction(Request $request): Response
    {
        $filter = $this->get(
            'prestashop.module.ps_custom.grid.filter.table.ps_custom_categories_articles'
        )->buildFiltersParamsByRequest($request);
        $grid = $this->get(
            'prestashop.module.ps_custom.grid.factory.table.ps_custom_categories_articles'
        )->getGrid($filter);

        return $this->render('@PrestaShop/Admin/Common/Grid/grid-layout.html.twig', [
            'layoutTitle' => 'PsCustomModuleCategoriesArticles',
            'help_link'   => false,
            'grid'        => $this->presentGrid($grid),
        ]);
    }

    /**
     * @param Request $request
     * @return RedirectResponse
     */
    public function searchAction(Request $request): RedirectResponse
    {
        /** @var ResponseBuilder $responseBuilder */
        $responseBuilder = $this->get('prestashop.bundle.grid.response_builder');
        return $responseBuilder->buildSearchResponse(
            $this->get('prestashop.module.ps_custom.grid.definition.table.ps_custom_categories_articles'),
            $request,
            'ps_custom_ps_custom_categories_articles',
            'admin.ps_custom.table.ps_custom_categories_articles.index'
        );
    }
}



Any idea how to fix search ?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...