raoul2000 / yii2-workflow

A simple workflow engine for Yii2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gridview filter dropdown

ferllings opened this issue · comments

Hello,

On my index page, I have a GridView widget, using an ActiveDataProvider object (from ->search() )
So I don't have any model object.
So, I did a bit of 'hack' to get the full list of statues:

$model = MyModel::find()->one();
	$allStatuses = WorkflowHelper::getAllStatusListData(
	 	$model->getWorkflow()->getId(),
	 	$model->getWorkflowSource()
	);

GridView::widget([
	'dataProvider' => $dataProvider,
	'filterModel' => $searchModel,
	'columns'=>[
		[
			'attribute' => 'status',
			'filter' =>$allStatuses,
		]
]
]);


Is there a better way to generate the dropdown filter menu that this?

Thanks

commented

Hi,
given a workflow Id, one option could be to directly get the list of all statuses from the workflowSource component (which wouldn't force to read a model from the DB). However this would be possible only if you're sure that MyModel is only associated with only one workflow, and that you know the ID of this workflow.
By default the workflowSource component has name "workflowSource".

Once you have a reference to the workflowSource just call getAllStatuses (see workflowHelper for example)

Hope it helps

Thanks that works well:

	$workflowSource = Yii::$app->get('workflowSource');

	$allStatuses = WorkflowHelper::getAllStatusListData(
	 	'MyWorkflow',
	 	$workflowSource
	);