How to extend Kartik GridView

Hi
I use Kartik DynaGrid and need to customize some aspect.
I create a file in my “app\components”

namespace app\components;

use Yii;
use kartik\dynagrid\DynaGrid;

class MiaDynaGrid extends DynaGrid {

    protected function applyPageSize() {
        ...
    }
    
}

and call it from view file with

use app\components\MiaDynaGrid as DynaGrid;

echo DynaGrid::widget([
...

When I go to the page using the component this i the output:

yii\base\ViewNotFoundException: The view file does not exist: C:\xampp_php7\htdocs\mia2\components\views\config.php in C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\View.php:233

Stack trace:
#0 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile('C:\\xampp_php7\\h...', Array, Object(app\components\MiaDynaGrid))
#1 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Widget.php(236): yii\base\View->render('config', Array, Object(app\components\MiaDynaGrid))
#2 C:\xampp_php7\htdocs\mia2\vendor\kartik-v\yii2-dynagrid\src\DynaGrid.php(1249): yii\base\Widget->render('config', Array)
#3 C:\xampp_php7\htdocs\mia2\vendor\kartik-v\yii2-dynagrid\src\DynaGrid.php(635): kartik\dynagrid\DynaGrid->initGrid()
#4 C:\xampp_php7\htdocs\mia2\vendor\kartik-v\yii2-dynagrid\src\DynaGrid.php(509): kartik\dynagrid\DynaGrid->initWidget()
#5 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Widget.php(140): kartik\dynagrid\DynaGrid->run()
#6 C:\xampp_php7\htdocs\mia2\components\MiaDynaGrid.php(18): yii\base\Widget::widget(Array)
#7 C:\xampp_php7\htdocs\mia2\views\procedura\index.php(85): app\components\MiaDynaGrid::widget(Array)
#8 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\View.php(348): require('C:\\xampp_php7\\h...')
#9 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\View.php(257): yii\base\View->renderPhpFile('C:\\xampp_php7\\h...', Array)
#10 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\View.php(156): yii\base\View->renderFile('C:\\xampp_php7\\h...', Array, Object(app\controllers\ProceduraController))
#11 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Controller.php(384): yii\base\View->render('index', Array, Object(app\controllers\ProceduraController))
#12 C:\xampp_php7\htdocs\mia2\controllers\GlobalController.php(462): yii\base\Controller->render('index', Array)
#13 C:\xampp_php7\htdocs\mia2\controllers\GlobalController.php(103): app\controllers\GlobalController->eseguiRender()
#14 [internal function]: app\controllers\GlobalController->actionIndex()
#15 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#16 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#17 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('', Array)
#18 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('procedura', Array)
#19 C:\xampp_php7\htdocs\mia2\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#20 C:\xampp_php7\htdocs\mia2\web\index.php(12): yii\base\Application->run()
#21 {main}

Why does it search the file “views\config.php” in the “app\components” instead of the “vendor\kartik\yii2-dynagrid” folder? And how can I solve it?

Thanks

Does someone can help me?

hey,
is your issue still present?
If so: please provide the complete code of \app\components\MiaDynaGrid

Yes, this issue is still present.
The code for “MiaDynaGrid” listed in first message is already complete. I’ll need to add some more function to it, but now it’s used just to overwrite, making it empty, the “applyPageSize” method.
Actually I found a workaround saving the file in “vendor\kartik-v\yii2-dynagrid\src” and assigning it to the “kartik\dynagrid” namespace, but I think it’s not a good idea to add file this way.

Well, I found a solution redefining the configView property in the initModule method.

<?php

namespace app\components;

use Yii;
use kartik\dynagrid\DynaGrid;

class MiaDynaGrid extends DynaGrid {

    protected function initModule() {
        parent::initModule();
        // '@vendor/kartik-v/yii2-dynagrid/src/views/';
        if (substr($this->_module->configView, 0, 7) != '@vendor') {
            $percorso = '@vendor' . substr($this->_module->getViewPath(), strlen(\Yii::getAlias('@vendor')));
            $percorso = str_replace('\\', '/', $percorso) . '/';
            $this->_module->configView = $percorso . $this->_module->configView;
        }
    }
    
    protected function applyPageSize() {
    }
    
}