Yii2 GridView separating html and data

Hello everyone. I’m working on a Yii2 project and using yii2 built in gridview for managing data. At this time, I want to separate html and data. In the other words, I need to make the gridview’s html in one action, and fill gridview with JSON rest data in another action. Is there any option in yii2 gridview for doing this?

I found a simiral question (json data) ,you can check the answer.

http://stackoverflow.com/questions/39508346/how-to-show-json-formated-data-in-gridview

Thank you for your response. But, I want to separate html and data completely. In fact, I want to have an action(url) for rendering just html file, and another action for just returning json data. So, in this approach, GridView should not fill on loading the page, and fill with an ajax request. So, the GridView should have an option for this.

If I understand right,you will do an action that load with ajax and this will have a view with the gridview,is not that?

GridView is not designed to do that.

You will have to write your own javascript to accomplish it, reading json data and filling each and every value to the corresponding cell of the table. The widget will not be called GridView any more, it will be a completely different thing.

If you want to use GridView, you would be better reconsider your design. Is it really required to send the content of the table in json format?