NoWaifuNoLaifu Posted November 29, 2024 Share Posted November 29, 2024 so in my module im trying to hide date_add column in the order table in the backoffice and replace it with date_upd so i did this: <?php use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\DateTimeColumn; use PrestaShop\PrestaShop\Core\Grid\Filter\Filter; use PrestaShopBundle\Form\Admin\Type\DateRangeType; if (!defined('_PS_VERSION_')) { exit; } class Updwebmania extends Module { public function __construct() { $this->name = 'updwebmania'; $this->tab = 'administration'; $this->version = '1.0.0'; $this->author = 'Webmania Solutions'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Commandes grid Webmania'); $this->description = $this->l("Masque la colonne par défaut 'Date' et la remplace par 'Date modification'."); // Define the context date format $this->contextDateFormat = $this->context->getContext()->getTranslator()->trans('Y-m-d H:i:s'); } public function install() { return parent::install() && $this->registerHook('actionOrderGridDefinitionModifier') && $this->registerHook('actionOrderGridQueryBuilderModifier') && $this->registerHook('actionAdminControllerSetMedia'); // Register this hook } public function uninstall() { // Unregister the hooks and perform cleanup return parent::uninstall() && $this->unregisterHook('actionOrderGridDefinitionModifier') && $this->unregisterHook('actionOrderGridQueryBuilderModifier') && $this->unregisterHook('actionAdminControllerSetMedia'); } public function hookActionOrderGridDefinitionModifier(array $params) { /** @var GridDefinitionInterface $definition */ $columns = $params['definition']->getColumns(); // Add the new "Date Updated" column $columns->addAfter( 'date_add', // Position after the 'date_add' column (new DateTimeColumn('date_upd')) ->setName($this->l('Date modification')) // Display name for the column ->setOptions([ 'field' => 'date_upd', // The field in the database 'sortable' => true, // Make the column sortable 'format' => $this->contextDateFormat, 'clickable' => true, // Make the column sortable ]) ); // Add a text filter for the "Date Updated" column $filters = $params['definition']->getFilters(); $filters-> add((new Filter('date_upd', DateRangeType::class)) ->setTypeOptions([ 'required' => false, ]) ->setAssociatedColumn('date_upd') // Link filter to the column ); } public function hookActionOrderGridQueryBuilderModifier(array $params): void { /** @var Doctrine\DBAL\Query\QueryBuilder $searchQueryBuilder */ $searchQueryBuilder = $params['search_query_builder']; // Add the date_upd field to the query $searchQueryBuilder->addSelect('o.date_upd'); /** @var Doctrine\DBAL\Query\QueryBuilder $countQueryBuilder */ $countQueryBuilder = $params['count_query_builder']; // Add the date_upd field to the count query $countQueryBuilder->addSelect('o.date_upd'); } public function hookActionAdminControllerSetMedia($params) { $controllerName = Tools::getValue('controller'); if ($controllerName === 'AdminOrders') { // Add custom CSS for styling (if necessary) $this->context->controller->addCSS($this->_path . 'views/css/admin/back.css'); } } } and this is the css : /* Hide the entire 'Date' column (header and cells) */ th[data-column-id="date_add"], td[data-column-id="date_add"], .date_time-type.column-date_add.clickable.text-left.cursor-pointer { display: none !important; } .input-group { display: flex; gap: 5px; } .input-group .form-control { width: 120px; } .input-group .input-group-text { background-color: #f4f4f4; border: 1px solid #ccc; } everything is working just fine but the filter is not working . it shows up but its not working for some reason, not only the filter but the sorting also Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now