Closed maz0717 closed 8 years ago
Tracked down the issue. The problem is that the database field names are being used to store the details and not the actual attribute names. If an attribute name is not the same as the database name, the saved sort will fail when the page is reloaded. I fixed the issue by changing line 1048 in DynaGrid.php from: $model->data = $isValidSort ? $sort->getOrders() : [];
to: $model->data = $isValidSort ? $sort->getAttributeOrders() : [];
I was previously using the build in yii2 gridview and have sorting setup on a related table using the following code in my "search()" function:
$dataProvider->sort->attributes['times_ordered'] = [ 'asc' => ['customer_info.times_ordered' => SORT_ASC], 'desc' => ['customer_info.times_ordered' => SORT_DESC], ];
Initial sorting works fine, when I save the sort, and return the the page, I receive the following error:
PHP Notice – yii\base\ErrorException
Undefined index: customer_info.last_order_date
Looking at the data saved in the database, it seems that the database key is being saved instead of the attribute.