When developing applications, it’s often essential to utilize a stable, unchangeable dataset, known in the coding world as static data. Integrating this kind of read-only data, akin to importing static data from Excel into apps, can seem daunting. But fear not! This guide will illuminate the process of defining static data in a code project, ensuring a robust foundation for your development endeavors.
Understanding Static Data in Code Projects
In a conventional canvas app, the data panel offers the facility to inject static Excel data seamlessly. This article delves deeper into the architecture of such static data, providing clarity on its code project representation.
Decoding the Sample Static Data
Consider a data table showcasing student names along with their respective exam scores. When this data gets incorporated into an app, its coded representation finds residence under the DataSources directory.
Unpacking the DataSources Directory
Previously, we discerned that the DataSources directory is a treasure trove of JSON schema representations. It captures every data source an app can connect to, be it SharePoint, SQL Server, or others. Additionally, any static datasets are also cataloged here, each carved into a distinct JSON file.
Dissecting the JSON Content
Let’s say our static data is labeled ‘ExamResults’. The critical components of such a JSON file might comprise:
- Data – Houses a JSON array encapsulating the genuine data.
- IsSampleData – Determines if the data source is a preset sample in Power Apps. For custom static datasets, this remains perpetually false.
- IsWritable – Signifies the writability of the data source. Static data remains ever-read-only, translating to a constant false here.
- Name – Represents the identifier to call upon the data source in Power Apps formulas.
- OrderedColumnNames – Correlates with the original Excel or data schema.
- Schema – Deciphers the schema and datatype of every column present in the dataset.
Clarifying Column Data Types
One pivotal aspect to grasp is the articulation of the column data type. Within the schema section, an array enlists column denominations parallel to their respective data types, separated by colons. Such data types are abbreviated, e.g., ‘s’ signifies a string, ‘d’ represents a date, and ‘n’ stands for number.
Date Value Expression
An intriguing nuance to observe is the portrayal of date values. Dates are articulated in the Unix format. For instance, a date such as ’05/02/2021′ would manifest as ‘1619913600000’.
In Summary
Creating a static data source within an app involves forging a JSON file in the DataSources directory, conforming to the required schema of a static data source. The upper hand here is the facile modification of static data, thanks to the editing prowess of contemporary code editors. If the technical intricacies get overwhelming or you require further elucidation on static data definition, feel free to reach out to us. Our seasoned team is ever-eager to assist, ensuring your projects flourish without a hitch.