V
V
VicTHOR2021-06-17 17:23:15
Yii
VicTHOR, 2021-06-17 17:23:15

How to change handler route of kartik GridView or standard GridView?

I'm adding a GridView to the page via renderAjax and the column sorting contains the url of the action that renders the GridView, and not the one on the page of which it happens.

For example, a view is given along the route /user/index, on which js is connected. In this js, another route is requested - in which html with a GridView is returned /user/components/detail-infothrough renderAjax and sorting in it leads to , and not to . How to fix? /user/components/detail-info?sort=/user/index?sort=

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2021-06-21
@VicTHOR

you pass the DataProvider to the GridView, the DataProvider has a sort property that takes a Sort object, for example:

new DataProvider([
   'query'=>...
   'sort'=> new Sort([
      'route'=>'/user/index'
   ])
])

sort has such a parameter as route - work with it,
then the sorter will contact the router that you specify to display new data.
or you can not initialize a new class, but do this:
new DataProvider([
   'query'=>... ,
   'sort'=> [
      'route'=>'/user/index'
   ],
])

here is the link to the documentation: https://www.yiiframework.com/doc/api/2.0/yii-data-sort

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question