P
P
PttRulez2019-07-24 20:45:07
Yii
PttRulez, 2019-07-24 20:45:07

Yii2. Custom table. Should I use GridView?

Hello. Tell me, in Yii2 it always makes sense to make a table through GridView? Or is it needed only when the Table repeats a table from the database or is a gluing of several tables from the database?
I would like to use the filters and features that gridview and searchmodel provide for filtering data. It would also be useful for me, because I'm learning the framework, using an example to understand how the widget works. But I'm not sure if it should be used in my case.
In a gridview, typically a row is one instance of the model, and a column is one of its attributes.
My task is something like this:
Each cell is just echo $model->name . $model->attribute4
Columns are the values ​​of one of the attributes of the model (in the first column, only those models whose attribute2 is equal to 0, in the second, those whose attribute2 is equal to 1, etc.)
You also need to group them internally by attribute # 3. That is, make it look like a merged cell. Here is an example table prototype:
o9b75W70GK.jpg
You need to implement filtering by various attributes. Attributes for presentation and filtering can be both from the table of the model itself, and from related tables
. Please tell me in which direction to study the material and which one in order to implement this. The most custom widget I've seen is the demos.krajee.com/group-grid pic , but the examples I see suggest it's not what I need
I even made a table with data output somehow. Ugly, but what you need, shows. I just collected a triple nesting array and made a div-layout through nested foreach. I still don’t know how to implement filtering, but I can either study the Internet on how to do it simply in php (but rather ys jquery) or on the topic of gridview from yii2. In gridview, it's cool that the table is already beautifully styled and filtering / sorting works correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gennady S, 2019-07-28
@gscraft

It is difficult to understand the problem in general, however. Does it make sense to work with GridView? This is a rather flexible mechanism, if not everything, then a lot can be implemented, and without resorting to external libraries in the Yii2 ecosystem. So, for example, with a head-on solution, you can define your own models with data and for filtering, inheriting from yii\base\Model , passing the ArrayDataProvider widget and custom fields in columns with "catching" grouping models. See what can be customized https://www.yiiframework.com/doc/api/2.0/yii-grid-... and the yii\grid\DataColumn documentation, you can define just about anything, right down to the HTML table attributes. Of course, there are more flexible libraries for working with tables, especially in JavaScript, but in your case, it seems that a significant share of the work falls on the controller, where you can also create columns for the table along the way using the Yii2 toolkit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question