12: Add checkboxes
You know what would be awesome? If we could select specific records in the grid and activate and deactivate them all at once. For those following along, this would be helpful to Valerie if she was sending multiple cars to maintenance at the same time - she could mark all of them as inactive all at once, rather than choosing individual records to change. So let’s set that up!
Add a Checkbox Column
- From the Car List screen, click Customize.
- Select GridCar. In the properties panel on the right, expand the Columns header and click "Has a checkbox column".
And now each row has a checkbox column! That was easy. Now, let’s set up some buttons to do something with those checked rows. First we need a separate section for the buttons.
Add a New Section
- Drag a new Section right above SectionList.
- Select the section and rename it SectionGridActions, remembering to hide the Header/Title bar.
- Change the padding to 1x EXCEPT FOR THE BOTTOM padding. We want it nice and close to the grid.
- Select the section named SectionList and change the Top Padding to None.
Okay, the section is all set up. Now onto the button!
Add a Button
- Drag a button object into SectionGridActions.
- Select the button and change its Text to “Deactivate”
- Change the Text Size to Small.
- Now, go into the Click event of the Deactivate button.
Let's start plotting actions. This next action we’re going to use is called a loop. A loop is a way for Method to perform the same action a set number of times. In this particular case, we want to perform an action for each record the user has checked in the GridCar.
Add Action Loop Through Gird
- Add the action Loop Through Grid.
- Step 1 asks us which Records we wish to loop through. We want the ones in the GridCar grid, so select that.
- In Step 2, check the checkbox: Only select rows that are checked.
- Make sure to add your Internal Note: “Loop through checked rows”
- Click Save & Back.
Now this loop will go through each checked record in the grid. If you checked three rows, the loop will run three times: once for each row. Of course, we want it to run an action for each row, so let’s add that next.
Add Action Update Fields in Table
- Add the action Update Fields
- Click Save & Back.The action isn’t configured yet, but there’s a step we need to take before we complete that process.
- Drag the “Update Fields in Table” action so that it is indented underneath the Loop.What does this mean? For each record you check in the grid, it will apply the “Update Fields in Table” action! Let’s program that action now.
- Click the pencil beside the action “Update Fields in Table”
- Step 1: For table, choose “Cars”.
- Step 1: For Where, select Open Criteria Builder.
- Criteria Builder 1st Value should read: “Field” “RecordID”.
- Criteria Builder Comparison should be the default setting: “Equals”.
- Criteria Builder 2nd Value will be: “Loop” “RecordID”. Once this is done, click Save & Back.
- Step 2 is Add a Field. For Field, let’s choose IsActive. The Value From should be Yes/No, and the Value will be No. This means for each record checked in the grid, Method will set its IsActive field to “No”, effectively deactivating the record!
- Make an Internal Note “mark checked records as inactive”, then click Save & Back.
Add Action Refresh Grid
The last thing we should do is add a Refresh the Grid action. This won’t be in the loop, by default, but you’ll want to make sure it isn’t (do not indent it), because we only want Method to refresh the grid once, at the end of the loop. If it ends up in the loop, Method will refresh the grid every time we process a record - and that becomes a real pain for everyone involved.
- Add the action - Refresh Grid.
- For Grid, choose “GridCar”.
- Click “Clear all checkboxes” – this will get rid of all the checkmarks in the check boxes when the grid refreshes.
- Make an Internal Note: “Refresh GridCar”.
- Then click Save & Back > Save & Close > Save > Close.
Add a New Button to Activate Selected Records
We now have a button designed to deactivate selected records, so logic would dictate we’d also want a button to reactivate selected records too, right? It certainly would, but here’s the thing: the process to create the Activate button is almost exactly the same as the process we just went through. So instead of walking you through all those steps again, here are the pertinent changes:
- On Step 2, select the button and change its Text to “Activate”.
- On Step 19, the Value should be set to “Yes”.
- On Step 20, make an Internal Note “mark checked records as active”.
All the other steps are exactly the same.