Config_filter.yaml file questions

So I am trying to figure out how i can predefine a filter to a list of data. From reading the documentation I have found that this is handled through the config_filter.yaml file.

The current code for the specific column of data I wish to adjust is below.

scopes:
  filterJobStatus:
    label: Job Status
    modelClass: Vektar\Crm\Models\AddJobStatus
    type: group
    conditions: add_job_status_id in (:filtered)
    nameFrom: add_job_status

I would like to adjust the conditions to reflect the status of Production, Pre Production, Post Production when the list is first displayed. I have tried modifying with some of the examples shown in the documentation however all I have managed to do is limit the choices to the three required when clicking on the dropdown list where you can apply filters. Is this possible?

Hey @dblackmon

You can use the default property in your scope definition to pre-select filter values when the list first loads. For a group type, pass an array of the database IDs for the records you want pre-selected:

scopes:
  filterJobStatus:
    label: Job Status
    modelClass: Vektar\Crm\Models\AddJobStatus
    type: group
    conditions: add_job_status_id in (:filtered)
    nameFrom: add_job_status
    default:
      - 1
      - 4
      - 7

Replace 1, 4, 7 with the actual primary key IDs of your “Production”, “Pre Production”, and “Post Production” records from the add_job_statuses table.

This will pre-filter the list on first load while still allowing all statuses to be selected from the filter dropdown. Once a user manually changes the filter, their selection is stored in the session and takes over. Clearing all filters resets back to the defaults.

Here’s an example from a helpdesk ticket system that defaults the status filter to show only active (non-closed) tickets:

1. The filter scope YAML (config_filter.yaml) defines the scope and points to a model scope:

scopes:
  status:
    label: Status
    type: balloonSelector
    modelClass: Acme\Helpdesk\Models\Ticket
    modelScope: filterByStatus
    options: getStatusFilterOptions

2. The controller sets the default value via listFilterExtendScopes:

public function listFilterExtendScopes($filterWidget)
{
    if ($scope = $filterWidget->getScope('status')) {
        $scope->defaults = 'active';
    }
}

3. The model scope receives that value and translates it into a query:

public function scopeFilterByStatus($query, $scope)
{
    $value = is_object($scope) ? $scope->value : $scope;

    if ($value === 'active') {
        return $query->where('status', '!=', static::STATUS_CLOSED);
    }

    return $query->where('status', $value);
}

The YAML modelScope: filterByStatus is what connects the filter widget to scopeFilterByStatus on the model. The controller just sets the initial value.

2 Likes

So not to sound stupid however I didn’t find anything in the documentation that would even suggest to me to try this approach. I am really struggling to understand the October CMS development. Im thinking I need to pass a SQL statment or create a view and display it.