In Yii2, while you use gridview widget to display your table data, for performing any operation on the record by selecting the checkbox, gridview assign the value of the first column retrieved from your the result set.
But you need to set some different value to the checkbox, so to do that you can use the below code
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => '\kartik\grid\CheckboxColumn',
'checkboxOptions' => function($model, $key, $index, $widget) {
return ["value" => $model['id']]; // this can be substituted with any column value of your result data
},
],
'name',
['class' => 'yii\grid\ActionColumn'],
],
]);
instead of the default one
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => '\kartik\grid\CheckboxColumn',
'mergeHeader'=>false
],
'name',
['class' => 'yii\grid\ActionColumn'],
],
]);
Insights
Yii2 how to set custom value for checkbox in gridview widget
Turn insight into action
Need help with cms or a related project?
If this article sparked an idea, question, or project direction, I can help you turn it into a practical next step.
Most recent
Latest posts from the blog
Why a headless CMS fits a personal brand website
A personal website can feel warm and editorial while still being structured, fast and easy to manage behind the scenes.
Read articleWhat matters in a WordPress blog migration
The migration is not only about moving posts. URLs, assets, authors, metadata and redirects all protect long-term search value.
Read articleMicrosoft Makes OpenAI’s $200/Month AI Free for All Copilot Users
Microsoft has recently made significant advancements in AI accessibility by integrating OpenAI’s advanced o1 model into its Copilot feature, now available for free to Windows users. Previously, unlimited access to this model required a subscription costing up to $200 per month. The o1 model, released in December 2024,
Read article



