Bumped on this thread. This site helped me a lot. The 2nd return is the correct format for the optgroup of kartik select2. https://demos.krajee.com/widget-details/depdrop#depdrop-action
// inside the controller
public function actions()
{
return \yii\helpers\ArrayHelper::merge(parent::actions(), [
'subcategory' => [
'class' => \kartik\depdrop\DepDropAction::className(),
'outputCallback' => function ($selectedId, $params) {
return [
[
'id' => 1,
'name' => 'Car',
],
[
'id' => 2,
'name' => 'bike',
],
];
// if using with optgroup return something like below instead of above
return [
'group1' => [
['id' => '', 'name' => ''],
['id' => '', 'name' => '']
],
'group2' => [
['id' => '', 'name' => ''],
['id' => '', 'name' => '']
]
];
}
]
]);
}
Happy coding!