'Yii2 render site based on id

hope there is someone that can help me. im trying to render a site after i clicked on my gridview and it works fine but can´t seam to get it render properly and im not sure if my function in controller is correct becoures i need to render the site based on category id with date for another table. my url is /web/index.php?r=site%2Fsubcategory?id=1

my view

<?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'rowOptions'   => function ($model,) {
                        return ['data-id' => $model->id];
                    },
                    'columns' => [
                        [
                            'header' => 'Titel',
                            'attribute' => 'name',                            
                        ],
                        [
                            'header' => 'Beskrivelse',
                            'attribute' => 'description'
                        ],
                        
                    ]
                ]) ?>      
            </div>
                    
        </div>

    </div>
</div>
<?php
$this->registerJs("

    $('td').click(function (e) {
        var id = $(this).closest('tr').data('id');
        if(e.target == this)
            location.href = '" . Url::to(['site/subcategory']) . "?id=' + id;
    });

");?

Controller function

public function actionSubcategory($id)
    {
        
        $category = new Category();
        $category->getCategorybyid($id);
        $Subcategory = new Subcategory();
        $dataProvider = new ActiveDataProvider([
            'query' => $Subcategory->getSubcategory(),
            'pagination' => [
                'pageSize' => 20,
            ],
        ]);
        return $this->render('subcategory', [
            'dataProvider' => $dataProvider]);

    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source