Building a PCF Control Grid View in Power Apps

PCF Control Grid View - Complete Guide

Building a PCF Control Grid View in Power Apps

Overview
This project demonstrates how to build a reusable PCF Dataset Grid using React, TypeScript and the Power Apps Component Framework. The control displays Dataverse records with custom search, pagination, toolbar, refresh button and responsive styling.

Technology Stack

Step 1 - Create PCF Project

pac pcf init --namespace Demo --name EventsGrid --template dataset
cd EventsGrid
npm install

Step 2 - Folder Structure

The project is organized into reusable folders for better maintainability.

Blog content image
Folder / FilePurpose
componentsContains all reusable React UI components.
Grid.tsxMain grid responsible for rendering rows and columns.
GridCell.tsxDisplays an individual cell value.
GridHeader.tsxDisplays column headers and sorting.
Pager.tsxHandles pagination logic.
SearchBox.tsxProvides record search functionality.
Toolbar.tsxContains Refresh and action buttons.
generated/ManifestTypes.d.tsAuto-generated PCF manifest types.
models/GridTypes.tsStores interfaces and model definitions.
services/DatasetService.tsRetrieves records from Dataverse Dataset API.
styles/Grid.cssContains all grid styling.
ControlManifest.Input.xmlDefines dataset, resources and control configuration.
index.tsEntry point of the PCF control.

Step 3 - Grid Component (Grid.tsx)

This component renders the entire grid.

const Grid = () => {
 return (
   <table>
      <thead>...</thead>
      <tbody>
         {/* Render Rows */}
      </tbody>
   </table>
 );
};

Step 4 - Grid Header

const GridHeader=()=>{
 return(
   <thead>
      <tr>
        <th>Name</th>
        <th>Created On</th>
      </tr>
   </thead>
 );
}

Step 5 - Grid Cell

const GridCell=({value})=>{
 return <td>{value}</td>;
}

Step 6 - Search Box

Filters records based on user input.

const SearchBox=()=>{
 const [text,setText]=useState("");
}

Step 7 - Pagination

const Pager=()=>{
 return <button>Next</button>;
}

Step 8 - Toolbar

const Toolbar=()=>{
 return <button>Refresh</button>;
}

Step 9 - Dataset Service

Responsible for reading dataset records.

export class DatasetService{
  public getRecords(context:any){
      return Object.values(context.parameters.dataset.records);
  }
}

Step 10 - Styling

table{
 width:100%;
 border-collapse:collapse;
}
th{
 background:#4B1FA2;
 color:#fff;
}
td{
 padding:10px;
 border-bottom:1px solid #ddd;
}

Step 11 - Manifest Configuration

<control namespace="Demo"
 constructor="EventsGrid"
 version="1.0.0">
</control>

Step 12 - Main Entry (index.ts)

public updateView(context:ComponentFramework.Context<IInputs>):HTMLElement{
   const records=context.parameters.dataset.records;
   return this.container;
}

Step 13 - Build & Test

npm run build
npm start(for local test)
pac pxf push(import and publish to Environment)

Step 14 - Final Grid View

Blog content image

The completed control displays Dataverse records in a modern responsive grid. The implementation includes search, refresh, pagination, record count, reusable components and Dataset API integration.

Project Flow

  1. Create PCF Project
  2. Create Folder Structure
  3. Create Components
  4. Create Dataset Service
  5. Create Models
  6. Add Styling
  7. Configure Manifest
  8. Implement updateView()
  9. Build Project
  10. Test in Harness
  11. Deploy to Power Apps

Future Enhancements

Conclusion

The PCF Control Grid View provides a flexible and modern approach for displaying Dataverse records in Power Apps. By leveraging the Power Apps Component Framework, developers can build highly interactive, reusable, and responsive controls that significantly improve the end-user experience compared to standard grid controls.

Success Tip: Always test your PCF control using the local test harness before deploying it to your Power Apps environment.