Disabling Trash/Delete in addModalAction on Grid/CRUD on a single row


I have a User-grid where I’ve added 2 addModalActions (Edit and Delete). I want to disable the Delete icon for the line where the current logged in user is listed, It’s stupid to be able to delete your active administrative user! :slight_smile:

Anyway, I’ve solved it using the following code but wondered if there is a better “ATK” way of doing it?

        new \atk4\ui\jsExpression("
    row = document.body.querySelector('[data-id=\"$user_id\"]');
    trash = row.querySelector('div.b_atk_admin_form_grid_view_table_actions_action_2');

Thanks in advance.


I usually set the canUpdate and/or canDelete flags to false and then use the addAction function to manually add the buttons. You can use the Multiformat function to hide/show/disable buttons as needed based on a field in the current row.

gcooka, I’d love to try this with Multiformat, but I really can’t find any demos/examples where this is used to changing the status of modalActions.

Can you please help out?

Thanks in advance,

I’m using 1.6.0 so code may be different with later versions. This code will only show the buttons if they are authorized to use them; could be modified to show them always but disabled when needed.

/* $a automatically refers to the model associated with the grid.  Using the b_atk_centered_grid_view_table_actions_action_edit (which is what atk would generate for the Edit popup) lets you use the built-in atk editing form */
$grid->addColumn('Actions', ['Multiformat', function($a, $b) {
	$return = '';
	if($a['CAN_EDIT'] == true)
		$return .= '<div class="ui b_atk_centered_grid_view_table_actions_action_edit compact icon button" title="Edit"><i id="atk_icon" class="edit icon"></i></div>';
	if($a['CAN_DELETE'] == true)
		$return .= '<div class="ui b_atk_centered_grid_view_table_actions_action_trash compact icon button" title="Delete"><i id="atk_icon" class="red trash icon"></i></div>';
	/* when showing a variable number of buttons, "right aligned collapsing" causes them to be right-aligned for aesthetic purposes */
	return [[
		'Template', $return, 'attr'=>['all'=>['class'=>['right aligned collapsing']]]
}], ['caption' => ' ']);
/* $vp_Edit is my virtual page for editing */
$grid->table->on('click', '.b_atk_centered_grid_view_table_actions_action_edit', function ($j, $id) use ($grid, $vp_Edit) {
	return new \atk4\ui\jsModal('Edit', $vp_Edit, ['edit_id' => $id]);
}, [$grid->table->jsRow()->data('id'), 'confirm' => false]);
$grid->table->on('click', '.b_atk_centered_grid_view_table_actions_action_trash', function ($j, $id) use ($grid, $m_Model) {
	/* gives the grid time to refresh.  Or instead could use the return $jschain->closest('tr')->transition('fade left'); code in \src\CRUD.php to delete without table refresh */
	return [
		new \atk4\ui\jsReload($grid->container)
}, [$grid->table->jsRow()->data('id'), 'confirm' => 'Do you confirm you wish to delete this item?']);
1 Like


That got me looking down the correct path!
Though, I think there should be a cleaner way of doing it ATK-style instead of div/js-style?


I’m glad that helped!

Re: div/js-style: Probably. Although, rather ironically I use divs and classnames to make use of ATK looks for, to use its standard features elsewhere :slight_smile: