Cannot change field which is "filtered out"

Following situation:
I have a grid view which shows all tickets but filtered out with agent_id = (my id). The filter is defined by a stickyGet(‘viewfilter’)=‘mytickets’. The grid view has an action button which adds a modal view to assign the ticket to someone else, i.e. change agent_id.
When you press save, atk4 throws an error that it does not find the specified ticket id in the model (which is correct, as I filter it out in the model) - however, the changed agent_id is not ultimately stored?!

How can I perform this? Here are the code excerpts:
$model = new Ticket($app->db);
$action = $app->stickyGET(‘viewfilter’);

switch ($action) {
case ‘all’:
$viewtitle = ‘All Tickets’;
break;
case ‘allopen’:
$viewtitle = ‘All Open Tickets’;
$model->addCondition([[‘ticket_status_id’, ‘<’, 50],[‘unread_message_count’,’>’,0]]);
break;
case ‘allmy’:
$viewtitle = ‘My tickets — ‘.$app->auth->user->get(‘name’);
$model->addCondition(‘agent_id’, $app->auth->user->get(‘agent_id’));
break;
default:
$model->addCondition(‘agent_id’, $app->auth->user->get(‘agent_id’));
$model->addCondition([[‘ticket_status_id’, ‘<’, 50],[‘unread_message_count’,’>’,0]]);
$viewtitle = 'My open tickets — '.$app->auth->user->get(‘name’);
}

$grid = $app->add(‘Grid’);
$grid->setModel($model, false);

$grid->addModalAction([‘icon’=>‘user edit’], ‘Delegate ticket’, function ($v, $id) use ($grid) {
$grid->model->load($id);

$modalform = $v->add('Form');
$modalform->setModel($grid->model, false);
$modalform->addHeader($grid->model['name']);
$gr = $modalform->addGroup(['width' => 'two']);
$gr->addField('team_id', [DropDown::class, 'caption' => 'Team', 'width' => 'four']);
$gr->addField('agent_id', [DropDownCascade::class, 'cascadeFrom' => 'team_id', 'reference' => 'Teammember', 'caption' => 'Account Manager', 'width' => 'four']);

$modalform->onSubmit(function($form) use ($grid,$v) {
    $grid->model->save();
	//$grid->js()->reload();

    return [
        $v->owner->hide(),
		new \atk4\ui\jsReload($grid)

    ];
});

});

The error caused reads like this:
Critical Error
atk4\data\Exception [code: 404]: Record was not found
Exception Parameters

model :Object atk4\login\app\Ticket

id :“2926”

conditions :[[“agent_id”,“3”],[[[“ticket_status_id”,"<",50],[“unread_message_count”,">",0]]]]

If you change agent_id value which is part of the condition, it’s going to throw that error. What you might can do is create first create a clone of the model before adding the conditions that could later change, and then save to it during onSubmit.

This is misuse of data-sets.

When you apply conditions (and filter does that), you reduce set of records that model can “access”. So saving data outside of that set is not allowed.

This is probably a bug in filter - it should restrict scope only for listing records, not for editing.

also - check out “saveAs” method for the model, although it won’t work out of the box for the filter.

I tried to clone the model as suggested which indeed would enable to save a changed (filtered) column field. However, now I have the issue that the paginator of the Grid (with cloned, filtered model) behaves completely strangely: Can’t select some pages, as the paginator is probably defined on the main model (and not the cloned)?? Any idea how we can solve this?

You might have luck changing \atk4\ui\jsReload($grid) to \atk4\ui\jsReload($grid->container). That resolved some issues I was having reloading grids and their ancillary elements.