Purpose: Show and Hide "inserted button" based on field's value on Grid
We will focus on how to show and hide the custom button based on the account_balance field value on each row of the Grid. (We will skip the custom button's events).
Step 1. Go to Page Designer, and insert a custom button [b]email_reminder_button to the row on the grid[/b]
The grid looks like this:
cust_id | cust_name | email | account_balance | email_reminder_button
Step 2. Take note of the item id of the inserted button:
Select the custom button by clicking on it once and take note of item id on the right panel.
In this example, our item id is email_reminder_button
Step 3: Copy the example codes to be used later in your event:
On the same right panel, click the ? mark on the right of "item id" to show how to hide and show the custom button on the grid, it will look similar to the below codes, copy it:
// Hide button:
$pageObject->hideItem("email_reminder_button", $recordId);
// Show button:
$pageObject->showItem("email_reminder_button", $recordId);
Step 4: In [b]After Record Processed event, paste the copied code above to conditionally hide the custom button:
[/b]
// for debugging: show the current row's data:
// echo "Debug row data: ".json_encode($data);
// Get the value of the condition data from current row, in our case, we use account_balance field:
$account_balance = $data["account_balance"];
// ### To add more condition checks from another table, run your SQL here. ###
/*
// Eg:
$id = $data["id"];
$sql = "select * from other_table where active=1 and other_foreign_key_id = $id";
$rs = DB::Query($sql);
$data_checked =$rs->fetchAssoc();
if($data_checked) { $active = 1; }
else { $active = 0; }
// Condition checks with other table field:
if ( $account_balance < 120 AND $active == 1)
*/
// ### To add more condition checks from another table, run your SQL here. ###
if ( $account_balance < 120 )
{
// paste the code from step 3 to show the button
$pageObject->showItem("email_reminder_button", $recordId);
}
else
{
// paste the code from step 3 to hide the button
$pageObject->hideItem("email_reminder_button", $recordId);
}
5. That's all you need to do. The custom buttons will now show and hide based on its row value on the list/grid page.