Customizing Modern Power Pages Lists using Client APIs

Modern lists in Power Pages are now Generally Available (GA). Even though they look cleaner and load faster than classic list, in real-world portal projects, their default grid views can be quite basic and don’t always cover what you need.

For example, if you want to style priority fields as status badges, hide specific rows based on status codes, change column headers, or show extra record details when someone clicks a row, this won’t be possible with out of the box configurations.

For classic lists, this type of customisations was done using jQuery scripts to manipulate HTML elements directly. But for modern lists, with the Power Pages Client API (Microsoft.PowerPages.onPagesClientApiReady), there are supported JavaScript objects and events that allow customizing modern lists cleanly.

What You Can Do with the Client API
The Client API gives you control over list containers, columns, rows, and cells. Some of the possibilities below:

List-Level Controls (IList)

  • Check list type: You can se list.isModern to verify if the list is a modern list before running custom scripts.
  • Control visibility: You can show or hide an entire list using list.setVisible(true/false).
  • Access the container: You can get the raw HTML element using list.getHtmlElement() and place custom elements (like a details panel) right around the table.

Column Controls (IColumn)

  • Rename headers: You can change the column header text with column.setHeader(‘New Title’).
  • Set tooltips: You can add header tooltips with column.setTooltip(‘Help text’).
  • Hide columns: You can toggle column visibility using column.setVisible(false).

Row Controls (IRow)

  • Read record data: Get raw Dataverse values using row.getValue(‘schema_name’) or formatted strings using row.getDisplayValue(‘schema_name’).
  • Check permissions & status: Detect for a user the server privileges (canWrite, canDelete) using row.getPrivileges(), or read stateCode and statusCode using row.getState().
  • Style and filter rows: Handle CSS classes (addClassName, removeClassName), handle inline styles (setStyle), or hide specific rows (setVisible(false)).

Cell Controls (ICell)

  • Override text: Change display text using cell.setDisplayText(‘Friendly Value’) without altering Dataverse data.
  • Apply cell styles: Change font weight, padding, or background colors using cell.setStyle().

List Events

  • loaded: Fires after the grid finishes fetching and rendering data (including initial load, sorting, filtering, and paging). Best place to handle reading row data or apply styling.
  • rowclick: Fires when a row is clicked, and you can get the record ID (e.row.getId()).
  • cellclick: Fires when a specific cell is clicked (overrides rowclick for that selection).

Practical Example

Here is a scenario where we combine these APIs to format choice columns into visual badges, highlight active selections, and display a detail view underneath the grid.

Note: The script below uses a custom Support Tickets list (pnp_supporttickets) from my own setup, featuring schema names like pnp_name, pnp_details, and pnp_priority. You will need to take the core concept and swap out these schema names and option values to match your own Dataverse tables and columns.

This would be used as the Custom JavaScript of the list:

// Helper function to safely call the Power Pages Web API with the verification token
function safeAjax(options) {
    if (window.webapi && window.webapi.safeAjax) { return window.webapi.safeAjax(options); }
    const deferred = $.Deferred();
    shell.getTokenDeferred().done(function (token) {
        options.headers = Object.assign({}, options.headers, { "__RequestVerificationToken": token });
        $.ajax(options).done(deferred.resolve).fail(deferred.reject);
    }).fail(function () { deferred.rejectWith(this, arguments); });
    return deferred.promise();
}

// Customize Modern Lists via the Power Pages Client API
Microsoft.PowerPages.onPagesClientApiReady(async function ($pages) {
    // 1. Find the modern list on the current page
    const list = $pages.currentPage.lists.getAll().find(l => l.isModern);
    if (!list) { return; }

    let panel = null;
    let selectedTicketId = null;

    // 2. Inject a custom CSS class for row highlighting
    if (!document.getElementById("selected-row-style")) {
        $("<style id='selected-row-style'></style>").text(
            ".selected-row, .selected-row > * { background-color: #e5f1fb !important; }" +
            ".selected-row { box-shadow: inset 3px 0 0 #0078d4 !important; }"
        ).appendTo(document.head);
    }

    function highlightSelectedRow() {
        list.rows.forEach((row) => {
            if (row.getId() === selectedTicketId) {
                row.addClassName("selected-row");
            } else {
                row.removeClassName("selected-row");
            }
        });
    }

    // Helper to build or reuse a panel container directly below the list
    function getPanel() {
        if (!panel || !panel.closest("body").length) {
            panel = $("<div class='ticket-details-panel'></div>").css({
                margin: "16px 0",
                padding: "16px",
                background: "#f3f2f1",
                borderRadius: "8px",
                borderLeft: "4px solid #0078d4"
            });
            $(list.getHtmlElement()).after(panel);
        }
        return panel;
    }

    // 3. Handle row selection: highlight row and fetch record details
    list.on('rowclick', async (e) => {
        const ticketId = e.row.getId();
        selectedTicketId = ticketId;
        highlightSelectedRow();

        const targetPanel = getPanel();
        targetPanel.empty().append($("<p class='text-muted'></p>").text("Loading details..."));

        try {
            // Fetch extra record fields via Web API
            const ticket = await safeAjax({
                type: "GET",
                url: "/_api/pnp_supporttickets(" + encodeURIComponent(ticketId) + ")?$select=pnp_name,pnp_details",
                contentType: "application/json"
            });

            if (selectedTicketId === ticketId) {
                targetPanel.empty().append(
                    $("<h4></h4>").text(ticket.pnp_name || "Ticket Details"),
                    $("<p></p>").text(ticket.pnp_details || "No details provided for this ticket.")
                );
            }
        } catch (err) {
            console.error("Could not load details", err);
            if (selectedTicketId === ticketId) {
                targetPanel.empty().append($("<p class='text-danger'></p>").text("Could not load ticket details."));
            }
        }
    });

    // Map choice column values to badge styles (Replace these integer values with your choice values)
    const priorityStyles = {
        192350000: { backgroundColor: '#fde7e9', color: '#a80000' }, // High
        192350001: { backgroundColor: '#fff4ce', color: '#8a5a00' }, // Medium
        192350002: { backgroundColor: '#e5f1fb', color: '#004578' }, // Low
        192350003: { backgroundColor: '#dff6dd', color: '#0e5a0e' }  // Routine
    };

    // 4. Format cells and set tooltips when data finishes loading
    list.on('loaded', () => {
        highlightSelectedRow();

        const titleColumn = list.getColumn('pnp_name');
        if (titleColumn) {
            titleColumn.setTooltip('Select a row to view full details below');
        }

        list.rows.forEach((row) => {
            const badgeStyle = priorityStyles[row.getValue('pnp_priority')];
            if (badgeStyle) {
                row.getCell('pnp_priority')?.setStyle({
                    ...badgeStyle,
                    fontWeight: 'bold',
                    padding: '4px 12px',
                    borderRadius: '12px',
                    width: 'fit-content',
                    lineHeight: '1.4'
                });
            }
        });
    });
});

Results

We get a color coded list based on the priority of the items, plus when selecting a row we can see their details being loaded below the list:

Reference

Client API lists – Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *