ArtiGrid
v1.5

Condition of the action buttons

This example demonstrates how to apply conditional logic to the default action buttons (view, edit, delete) in ArtiGrid. By using the setActionCondition() method, you can control when each button is displayed based on the values of specific fields in each row.

Each condition is defined as an array with three elements: the field name, the operator, and the value to compare. For example, ['employeeNumber', '!=', 1370] means that the delete button will be shown for all rows except the one where the employee number is 1370.

This allows you to dynamically restrict user actions directly in the interface. In this example, different employee records have restrictions applied individually for delete, edit, and view actions.

The conditions are evaluated on the client side, ensuring a responsive experience without requiring additional server requests. You can also define multiple conditions to create more advanced rules if needed.

This feature is useful for implementing permissions, protecting specific records, or customizing behavior based on business logic.


<?php
    $grid = new ArtiGrid();
    $grid->table('employees')
        ->template('bootstrap5')
        ->unset('filter', false)
        ->setActionCondition('delete', ['employeeNumber', '!=', 1370])
        ->setActionCondition('edit', ['lastName', '!=', 'Hernandez'])
        ->setActionCondition('view', ['employeeNumber', '!=', 1501])
        ->modal();
    echo $grid->render();
?>
employeeNumber lastName firstName extension email officeCode reportsTo jobTitle Actions