Purpose: To disallow user edit of the data row, using "Is Record Editable" event, based on record row's data and user id
Is Record Editable event, when conditions return as FALSE, will automatically:
- Hide the edit buttons and prevent Inline Edit, Edit, Delete of the affected rows
- Redirect user to List page if user tries to access Edit URL directly
Step 1: Create a field name called "record_locked" in your table
You can use any field eg. Certified which will store 1 (Disallow edit) and 0 (Allow Edit).
Step 2: Go to [b]Is Record Editable Event and enter the code below[/b]
Is Record Editable Event:
// First, get the current logged in user data from the user table,
// you can use any field of your user table as long as it is unique.
// We use the id field and id=1 is our admin in this case.
$userData = Security::currentUserData();
$user_id = $userData["id"];
// Start the condition checks
if ($values["record_locked"] == 1 AND $user_id != 1)
return false;
else
return true;
That's all you need to do. If you want to also show a lock icon, proceed to Step 3.
Step 3 (Optional step): To display a lock icon when record_locked = 1
Go to Page Designer and click the record_locked field's View As/Edit As, and set the custom code below:
if ($value == 1 )
{
$value = "<li class='fa fa-lock'></li>";
}
else
{
$value = "";
}
Then, drag the record_locked field to the edit buttons box and remove the record_locked column:
Below is the final screenshot
Note: This can also extend to pages where you want the admin to have edit and not other people.
In this case, it's even easier, just use "Is Record Editable" to check for user id as the condition.