kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

How to check if a column is visible to the current user #233

Closed sokollondon closed 2 years ago

sokollondon commented 3 years ago

I need to get personal value of one field from DynaGridStore

$dataProvider = $model->search();

var_dump($model->status_id);//NULL   <-- How to get value here?

DynaGrid::widget([
    'options'=>['id'=>'post-index'],
    'gridOptions'=>[
        'dataProvider' => $dataProvider,
        'filterModel' => $model,
    ],
    'columns' => [
        'name',
        'status_id',
    ],
]);
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/95916082-how-to-get-personal-value-of-field-dynagridstore?utm_campaign=plugin&utm_content=tracker%2F2666393&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F2666393&utm_medium=issues&utm_source=github).
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sokollondon commented 1 year ago

This code checks if the column is visible to the current user

$dgSettings = new DynaGridSettings(
    [
        'moduleId' => 'dynagrid',
        'dynaGridId' => 'YOUR_dynaGridId',
        'storage' => DynaGrid::TYPE_DB,
        'category' => DynaGridStore::STORE_GRID,
        'userSpecific' => true,
    ]
);
$keys = $dgSettings->fetchSettings()['keys'];
if(!$keys) return null; //no personal settings for the user
$hashCol = hash('crc32', 'YOUR_COLUMN_NAME');
$isColumnVisible = array_search($hashCol, $keys)!==false;
var_dump($isColumnVisible);