PowerGrid
lowcodera PowerGrid Component
Purpose
Packed with features and customization options, the lowcodera PowerGrid takes presenting, interacting and editing your tabular data in Power Apps to a new level.
Binding Data
You can bind data to the PowerGrid using the items property. Simply select your data source like you would with any out of the box control like the Gallery or Data Grid.
PowerGrid Properties
Theme
Styles the grid with one of several themes.
Auto-Size
Size the grid columns with three different options
Auto-Size All – auto-sizes columns based on cell content and column name lengths
Auto-Size All (Skip Header) – auto-sizes columns based on cell content and ignores headers
Size to Fit – auto-sizes the grid content to fit the width of the component
Row Drag
Enables or disables the ability for end users to re-order rows by dragging rows
Grouped Rows
Enables or disables the ability for end users to use the row grouping function. The row grouping feature allows the data to be grouped by a column or hierarchy of columns.
Use Custom Grouping
Boolean to determine if rows should be grouped based on the column schema definition instead of what the end user does as run-time
Columns Sidebar
Enables or disables the ability for end users to see the columns sidebar. The columns sidebar allows users to select which columns to show in the grid at run-time
Filters Sidebar
Enables or disables the ability for end users to see the Filters sidebar. The filters sidebar provides advanced data filtering capability for users at run-time
Column Search
Enables or disables the in-column search function for users
Use Dataset API
Hide Toolbar
Boolean to hide or show the PowerGrid toolbar which is above the grid.
items
Used to bind to your data source
ColumnsDataSet_Items
Load All Rows
Preloads all rows instead of loading data on scroll
Font Size
Sets the font size of the grid content
Row Height
sets the height of rows for the grid
Set Filter
definition of the pre-defined filter settings to apply to the grid
filter
JSON output of the filters currently applied to the grid. Can be copied and pasted into Set Filter input property for setting predefined filters
onSelectedItems
Returns a collection of the items selected on the grid
onEventType
Outputs the current event which has been triggered on the grid.
actionButtonRowId
Returns the id of the row from where the user invoked an action button
Columns Dataset
The items property allows you to bind the grid to your data source and render it. In addition to this, there is some advanced functionality available in the PowerGrid which is unlocked through using the columns dataset property which is defined in JSON. Key attributes for our column dataset schema are documented below
Attribute
Description
DisplayName
Sets the display name of the column
IsKey
Boolean to define if the column is the primary key. Necessary when the API dataset method is not used to save records.
visible
Boolean to define whether the column is visible or not on the grid
editable
Boolean to determine if a column is editable or not
DataType
Defines the column Data Type. Supported values are: String
Number Date
Choices html rating actionButton
DataFormat
ConditionalFormatting
Choices
Used to provide a JSON data schema for any column defined with a datatype of Choices
rowGroupIndex
Integer to define the column grouping order for this column
showCheckbox
Boolean to determine if a checkbox is shown against the column
Example Schema
Saving Data
There are two approaches for saving data back to your data source- using the dataset API or by patching records via the OnChange Event. The Dataset API is simpler to use, however it is a new feature from Microsoft and there are some limitations which means it is not suitable for all situations.
Using the Dataset API
To use this method for saving data, make sure the “Use Dataset API” property is set to true and the Hide Toolbar property is set to false.
As users make changes to column values, the toolbar will show a count of unsaved row changes. Users need to press the save button in the toolbar to commit changes back to the underlying data source.
Saving via the OnChange Event
Before using this method:
Set the IsKey attribute to true for whichever the unique ID column is in your Columns Dataset.
Set the “Use Dataset API” property to false
Set the “Hide Toolbar” property to true.
This method requires PowerFX to be inserted into the OnChange event of the PowerGrid. There are 3 sections to the PowerFX code which are documented in the example code snippet below.
Generating a collection of changed rows
Generating a collection of changed values from the changed rows
Patching the changed values back to the data source
See below for an example code snippet for saving data via the OnChange Event:
Copy and Pasting Data
The grid supports copying and pasting data into it from data sources like Excel. The Ctrl + V keyboard shortcut will need to be used to perform the paste operation.
When data is pasted into the grid, there is a pastedData EventType which is exposed. This should be used in the OnChange event to process the pasted data. The pasted data is held in the onUpdatedItems output property, as per when any data is updated in the grid.
You will need to handle the two scenarios of when data is pasted into existing records and when pasted data is creating new rows. When the pasted data is creating a new row on the grid, the id attribute for that row of onUpdatedItems will be set to "NEW_ROW".
See the example PowerFx code below for how the OnChnage event of the grid can be used to process regular updates to the grid as well as from Copy and Paste operations.#
Conditional Formatting
The columns schema can be used to define cell based rules for conditional formatting. The example code snippet below shows how the background color of a cell can conditionally be defined
Supported operators
Relational operators
>
<
>=
<=
===
<> or !== or !=
Logical operators
&& or And
|| or Or
! or Not
‘value’ or ‘x’ is used for the content in the cell
Schema for conditional formatting JSON (conditionalFormat in column definition of the grid)
When there are overlapping regions then the later style takes the precedence
Any CSS attributes can be used inside the ‘ifTrue’ and ‘ifFalse’. Also use camelCase for the CSS attributes.
Data Formatting
Cell values can be formatted in the PowerGrid by specifying the appropriate expression in DataFormat attribute of the JSON column schema.
Decimal places
Use the expression below, where the number after d denotes the number of decimal places. The example below formats the numbers to 2 decimal places. dataFormat: "{{value:d2}}"
Thousand separators
A thousand separator can be specified by extending the decimal formatting expression with “:t”. The example below formats the numbes to 0 decimal places, with a thousand separator
dataFormat: "{{value:d2:t}}"
Prefixes
Values can also be prefixed into the expression e.g. Currency Symbol. The example below formats the number to 0 decimal places, with a thousand separator and a £ currency symbol
dataFormat: "£{{value:d2:t}}"
Dates
When the DataType is Date, various data formatting expressions can be used to format the date.
dataFormat:"DD-MM-YYYY"
Action Buttons
Action buttons allow you to define in-line interactive buttons within the grid. You can have one or more buttons per row and style each one independently. Importantly, you can also assign an event to a button and define PowerFx expressions to trigger when the user clicks on it.
Adding buttons
Action buttons can be defined in the Column Schema by setting the DataType attribute for a column to be “actionButton”
Action button attributes
event
Name of the event which can be used in the OnChange event formula
id
Unique of the event. Comes into use when conditional visibility rules are applied
variant
The style of the button. “Outline” or “Default”
tooltip
A tooltip description which will be displayed on hover
name
Text to appear on the button
disabled
Boolean to denote whether button can be clicked or not
icon
FontAweseome icon reference
fontColor
Color of text ad icon
backgroundColor
Background color of button
borderColor
Border color of button
width
Width of button in px
height
Height of button in px
fontSize
Size of text and icon
borderRadius
Radius of the button in px
margin
Margin between buttons
Handling user interaction
When a user clicks on an action button the PowerGrid onEventType property outputs the name of the event, as defined in the column definition. The actionButtonRowId output property also returns the id of the row the user has interacted with.
To handle the interaction, follow these steps:
Make sure you have defined a unique name for the action button in the event attribute
In the OnChange of the PowerGrid, add a PowerFx expression for when the onEventType is equal to the name of your event.
Use the actionButtonRowId output to perform your action against the appropriate row in your data source
See below for example, where the event has been called viewProfile
Setting Predefined Filters
The PowerGrid supports scenarios where you need the grid prefiltered. To enable this simply populate the Set Filter input property with the appropriate JSON expression.
To save you having to manually generate the JSON for the filter query, the easiest way of setting a predefined filter is to first of all apply the filter condition(s) to the grid as an end user. Then copy the string generated in the output property filter and paste this into the set filter input property
Using Pre-set Grouping
It's possible to have predefined column grouping on the grid. To enable this follow thee steps
Turn on the Use Custom Grouping property in the grid (set to true)
In the column schema, for each column you want to group by, set the rowGroupIndex attribute. This should be a number from 0 onwards for each column which will be grouped. See example below.
Limitations/Known issues
Saving decimal data is currently not supported by the new dataset API
Saving data to SQL data source is currently not supported the new dataset API
Under certain scenarios, changes on the grid are not reflected in real-time even though they are saved to the data source
Last updated