Subgrids Done Right
Subgrids show related records directly on a form. Here's how to add them, choose the right relationship, filter the records, enable inline editing, and set up a New button that pre-fills the parent lookup.
A subgrid is a grid of related records embedded in a model-driven app form. Open an Account and see its Contacts listed right there. Open a Project and see all Tasks. It’s the primary way users interact with related data without navigating away from the parent record.
Here’s how to set them up properly.
Adding a Subgrid to a Form
- Open your solution in make.powerapps.com.
- Open the table whose form you want to edit (e.g., Account).
- Go to Forms and open the Main form.
- In the form designer, select the section where you want the subgrid.
- From the left panel under Components, find Subgrid and drag it onto the form. Alternatively, click + Component and select Subgrid (1 column) or Subgrid (2 columns).
- A configuration panel appears on the right.
Configuring the Subgrid
- Table: Choose the related table to display (e.g., Contacts).
- Default view: Select which view to use for the subgrid. This controls which columns are visible and the default sort order.
- Related records vs All records:
- Related records: Only shows records related to the current parent record through a specific relationship. This is what you want 95% of the time.
- All records: Shows all records in the table, regardless of relationship. Useful for reference lookups but rare on forms.
- Relationship: If you chose Related records, pick the relationship that connects the two tables (e.g.,
account_contacts— Contacts related to this Account via the Company Name lookup).
Save and publish the form.
Choosing the Right Relationship
When you pick “Related records,” the designer shows you the available relationships. If there are multiple relationships between the same two tables, pick the right one:
- If a Contact has a
Company Namelookup pointing to Account, the relationship is something likecontact_customer_accounts. - If a Contact also has a
Secondary Accountcustom lookup to Account, that’s a different relationship.
Pick the one that matches the business meaning of the subgrid. If you pick the wrong relationship, the subgrid will show the wrong records — or no records at all.
Tip: If you don’t see the relationship you expect, make sure the lookup column exists on the child table and that the relationship was created in a solution that’s part of your current environment.
Controlling Which Columns Appear
The subgrid displays whatever columns are defined in the selected view. To change what users see:
- Go to the child table (e.g., Contacts).
- Open Views.
- Either edit the existing view that the subgrid uses, or create a new view specifically for the subgrid.
- Add/remove columns, set sort order, set filters.
- Save and publish.
- Back on the parent form, set the subgrid’s Default view to your new view.
Creating a dedicated view for subgrids is a good practice. The “Active Contacts” view might have 15 columns that make sense in a full-page grid but are too many for a subgrid. Create a “Contact Subgrid” view with 3-4 key columns.
Filtering Subgrid Records
Using the View Filter
The simplest way to filter subgrid records is through the view definition. If you only want to show active contacts in the subgrid, use the “Active Contacts” view (which has a built-in filter on status).
For custom filters — say, only show contacts where Role equals “Primary” — create a view with that filter condition built in.
Using JavaScript for Dynamic Filtering
If you need the subgrid filter to change based on form data (e.g., show different records based on a field value), you’ll need JavaScript:
function filterSubgrid(executionContext) {
var formContext = executionContext.getFormContext();
var subgridControl = formContext.getControl("Contacts_Subgrid");
if (!subgridControl) return;
var accountType = formContext.getAttribute("accountcategorycode").getValue();
// Build a FetchXML filter
var fetchXml =
'<fetch>' +
' <entity name="contact">' +
' <attribute name="fullname" />' +
' <attribute name="emailaddress1" />' +
' <filter>' +
' <condition attribute="customertypecode" operator="eq" value="' + accountType + '" />' +
' </filter>' +
' </entity>' +
'</fetch>';
subgridControl.setFilterXml(fetchXml);
subgridControl.refresh();
}
Register this on the form’s OnLoad event and on the OnChange event of the field that drives the filter.
Editable Grids
By default, subgrids are read-only — users can view records but need to open them to edit. You can enable inline editing:
- In the form designer, select the subgrid.
- In the properties panel, check Allow editing or look for the Editable grid option.
- Alternatively, replace the standard subgrid control with the Editable Grid (Power Apps Grid) control through the Controls tab.
With editable grids, users can click a cell and edit it directly in the subgrid. This is great for scenarios like entering time entries, updating quantities, or changing statuses in bulk.
Note: Editable grids respect field-level security and form-level business rules. If a field is read-only due to security or a business rule, it stays read-only in the editable grid too.
Pre-filling the Parent Lookup on New Records
When a user clicks the + button (New) on a subgrid, the system creates a new record of the child type. By default, the parent lookup is automatically populated — if you click “New Contact” on an Account subgrid, the new Contact’s Company Name field is pre-filled with the current Account.
This works automatically for the relationship defined on the subgrid. No configuration needed.
Custom “New” Button with Additional Pre-fill
If you want the New button to pre-fill additional fields beyond just the parent lookup, you need a custom command bar button. Using the Command Designer or JavaScript:
function createContactWithDefaults(primaryControl) {
var formContext = primaryControl;
var accountId = formContext.data.entity.getId().replace("{", "").replace("}", "");
var accountName = formContext.getAttribute("name").getValue();
var entityFormOptions = {
entityName: "contact",
useQuickCreateForm: true
};
var formParameters = {
// Pre-fill the parent lookup
parentaccountid: accountId,
parentaccountidname: accountName,
parentaccountidtype: "account",
// Pre-fill other fields
address1_city: formContext.getAttribute("address1_city").getValue(),
customertypecode: 1 // Set a default choice value
};
Xrm.Navigation.openForm(entityFormOptions, formParameters);
}
Bind this to a custom button on the subgrid’s command bar.
Subgrid Properties Worth Knowing
| Property | What It Does |
|---|---|
| Maximum rows | How many rows to show before scrolling (default varies, usually 4-10). Increase this for subgrids that typically have many records. |
| Show on phone | Whether to display the subgrid on the mobile form. Subgrids can make mobile forms slow — consider hiding them on phone layouts. |
| Default view | Which saved view to display. Users can switch views using the view selector if you allow it. |
| Allow users to change view | If disabled, users see only the default view. Enable this to let users switch between views. |
Common Mistakes and How to Fix Them
Subgrid Shows No Records (But Records Exist)
Check these in order:
- Relationship is wrong. The subgrid is using a different relationship than the one your data uses. Verify the lookup field on the child records actually points to the parent record.
- View filter excludes the records. The default view might filter by status (e.g., “Active Contacts Only”) and your records are inactive.
- Security. The user doesn’t have read access to the child records. Check security roles.
Subgrid Shows Records from the Wrong Parent
You selected the wrong relationship. If a Contact table has two lookups to Account (Company Name and Secondary Account), make sure the subgrid uses the relationship that matches the lookup your data populates.
”New” Button Creates a Record Without the Parent Filled In
This happens if the subgrid is set to “All records” instead of “Related records.” Change it to “Related records” and select the correct relationship. The parent lookup auto-fill only works with a defined relationship.
Subgrid Is Slow to Load
If the child table has many records and the view isn’t filtered well, the subgrid can be slow. Solutions:
- Use a view with tight filters (don’t show all records of all time)
- Reduce the number of columns in the subgrid view
- Reduce the maximum rows displayed
- Make sure the columns used in the view’s filter and sort are indexed
Editable Grid Changes Don’t Trigger Business Rules
Standard business rules don’t fire for inline edits in editable grids. If you need validation or field-level logic on inline edits, you’ll need JavaScript events registered on the editable grid control, or move the logic to a plugin that runs server-side on update.
Related articles
Field Visibility with Business Rules
Business rules are the fastest way to control field visibility and editability on model-driven forms without writing code. Here's how to set them up and avoid the common traps.
JavaScript in Model-Driven Apps: Patterns That Actually Matter
A senior D365 developer's guide to JavaScript in model-driven apps — form events, Xrm.WebApi, field manipulation, async OnSave, debugging, and the patterns you'll actually use in production.
Adding Custom Buttons to the Command Bar in Model-Driven Apps
Step-by-step guide to adding a custom command bar button to a Dataverse table in a model-driven app — using the modern Command Designer, no XML editing required.