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
  • Component
  • Initialize
  • Config
  • Example
  • DataBind

Was this helpful?

  1. Working with Components
  2. Building a Component

DataSets

PreviousData EventsNextIntroduction

Last updated 2 years ago

Was this helpful?

The code for the following examples are available in the project inside the \datasets folder.

encapsulate much of the plumbing for executing queries and responding to data changes on behalf of components. Datasets react to and send updates to components as standard . As a result, most components that need to handle data changes will leverage datasets for data binding.

Component

In order to leverage datasets for data binding, a component starts by extending the base class via the syntax below in JavaScript.

var myComponent = function () {

    const self = this;
    
    wire.ui.Component.call(this);

    ...    
}

Initialize

Next, initialize the base wire.ui.Component class by calling the init method which takes the following parameters.

Name

Description

element

The element passed into the render method.

config

dataBind

The function to call when data bound to the component has changed. This includes the initial binding.

Config

Name

Description

default

The default settings for the component's configuration.

user

The settings passed into the render method. These will override the default settings.

Example

The following is a full example of the initialize method being called in a component.

this.render = function (el, userConfig) {

    self.init({
        // Root element passed in
        element: el,
        // Merge user and default configs with user overriding the default
        config: {
            // This component looks for a person field in the data
            // The name of the field defaults to 'person'
            default: { datamap: { person: "person" } },
            // User override for any configuration
            user: userConfig,
        },
        // Function to be called when there is new data for the component
        // This includes the first time during initialization
        dataBind: _bind
});

DataBind

The _bind method set in the dataBind configuration above is detailed below in comments.

function _bind() {

    // Merged user and default configs with user overriding the default
    const cfg = self.config();

    // New data as a datatable
    const table = self.table();

    // Grab the first row
    const row = table.first();

    // Get a reference to the root DOM element
    // Use self.$element() to get a jQuery reference
    const el = self.element();

    // Add the data to the root element
    // Use the 'datamap' config property to reference the data in case the field name is different in the source data
    el.innerHTML = row ? row[cfg.datamap.person] : "";

    // Tell everyone the component is ready
    // Calls the 'ready' event if set in the configuration
    self.ready();

}

See section below.

The default configuration settings for the component will be merged with the ones passed in as part of the component binding. See for more information.

building-a-component
Datasets
standard data events
datatables
wire.ui.Component
Component - Config
Config