WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page
  • Field Properties
  • Entity Wildcards
  • Calculated Columns

Was this helpful?

  1. Reference
  2. wire.data

wire.data.DataModel

Using a data model is a convenient way to share meta data about the structures in a data services across all queries.

Field Properties

Name

Description

Alias

Used to register a friendly name for the field used in components and other UI containers

Calc

Entity

Identifies the entity or table in the data service

Name

Identifies the field name in the data service

Format

The example below sets up a data model on a data source. Alias names for labels and formatting are set up for fields in the data service. This meta data will automatically be applied to all fields in result sets for any query executed using the data source. As such they can automatically be leveraged by any components or other UI elements displaying the result sets.

const model = new wire.data.DataModel({
    Fields: [
        { Entity: "Metrics", Name: "cost_amt", Alias: "Cost", Format: "C2" },     
        { Entity: "Product", Name: "line_no", Alias: "Line" },
        { Entity: "Time", Name: "week_start_date", Alias: "Week", Format: ((value) => {
                return moment(value).format("MM/DD");
            })
        }
    ]
});

const source = new wire.data.DataSource("table", {
    ...
    Model: model
});

Entity Wildcards

Wildcards (*) can be used with a field's Entity property to apply the field model data to any field in any entity containing the field Name.

The example below will result in any field called Sales in any entity to be formatted as currency and with two decimal places.

const model = new wire.data.DataModel({
    Fields: [
        { Entity: "*", Name: "Sales", Format: "C2" }
    ]
});

Calculated Columns

The example below creates a new calculated column called ProfitMargin on the resulting datatable that is returned from any query that contains the entity Metrics. The calculation uses the existing Sales and Cost columns on the table to return the value for the new calculated column.

const model = new wire.data.DataModel({
    Fields: [
        { Entity: "Metrics", Name: "ProfitMargin", Format: "P0", Calc: (row) => {        
            return ((row.Sales-row.Cost)/row.Sales);
        }}             
    ]
});

const source = new wire.data.DataSource("table", {
    ...
    Model: model
});

const query = wire.data.select("Sales", "Cost").from("Metrics");

const table = await source.execAsync(query);
Previouswire.data.DataEventNextwire.data.DataPromise

Last updated 3 years ago

Was this helpful?

Creates a new calculated column on the returned by the data source. See for details.

The specification for the field

For more examples, visit .

formatting
datatable
Calculated Columns
DataSource DataModels