I have a gridview of jobs. Each job has a status. I am trying to code a solution to allow the status to appear as a dropdown in each cell of the gridview column. The dropdown should display the currently set status of each job. When I get this working then I will add a jQuery onchange event to save changes to the status to the database for the particular job.
My problem is that I have no idea how to pass a job’s set status_id to my model function which renders the dropdown.
My function in the model:
public function getStatuses($selectedStatus = null) {
$statusData = Arrayhelper::map(Statuses::find()->orderBy('status')->asArray()->all(), 'id', 'status');
$statusOptions = '';
foreach ($statusData as $key => $value) {
$statusOptions.= '<option value="'.$key.'"';
if ($selectedStatus != null){
if ($selectedStatus == $key) {
$statusOptions.= ' selected="selected"';
}
}
$statusOptions.= '>'.$value.'</option>';
}
return '<select class="form-control" style="min-width:130px;"><option>--</option>'.$statusOptions.'</select>';
}
So as you see I’m trying to use a function parameter to pass the status value.
In my gridview column I can’t figure out how to (or even if it’s possible to) pass the status value for the particular job row to the model function. This is what I’ve tried and it’s not working:
The resulting error is ‘[font=“Courier New”]Getting unknown property: backend\models\Jobs::statuses(status[/font]’
So what should I do to pass the set status value for a job to the getStatuses function in my Job model? Is the set status available in the model already somewhere for the gridview row, to be used? I’m not clear on how data is split between the view and the model and what’s accessible from where.
Any help will, as always, be immensely appreciated. Thanks!