Portal Community

widget.data Shape by Widget Type

DataGrid

widget.data = {
  rows: [              // Array of row objects from the data source
    { id: "lead-1", name: "Acme Corp", status: "active", dealValue: 15000 },
    { id: "lead-2", name: "Beta Inc",  status: "closed", dealValue: 8000 }
  ],
  total: 142,          // Total record count (for pagination)
  page: 1,             // Current page number
  pageSize: 20         // Records per page
}

// Accessing rows
function onDataChange(widget, variables, actions, context) {
  const rows = widget.data.rows;
  const activeLeads = rows.filter(r => r.status === 'active');
  console.log('Active leads on this page:', activeLeads.length);
}

Chart

widget.data = {
  series: [
    {
      name: "Q1 Revenue",
      data: [10000, 12000, 9500, 14000]
    },
    {
      name: "Q2 Revenue",
      data: [11000, 13500, 10200, 15800]
    }
  ],
  categories: ["Jan", "Feb", "Mar", "Apr"]
}

Form

widget.formValues = {      // Current field values
  leadName: "Acme Corp",
  contactEmail: "contact@acme.com",
  dealValue: 15000,
  status: "active"
}

widget.data = {           // Pre-fill data (if form loaded from a data source)
  id: "lead-123",
  name: "Acme Corp",
  ...
}

Single Value / Stat Widget

widget.data = {
  value: 142,            // The resolved scalar value
  label: "Open Leads",
  trend: "+12%"
}

Reading widget.props

widget.props contains the widget's resolved configuration — column definitions for grids, chart config, etc. It reflects the current state after token expressions have been evaluated:

// Reading column definitions from a DataGrid
function onLoad(widget, variables, actions, context) {
  const columns = widget.props.columns;
  console.log('Column count:', columns.length);

  // Find which columns are currently visible
  const visibleColumns = columns.filter(c => c.visible !== false);
  variables.set('visibleColumnCount', visibleColumns.length);
}

Handling Empty Data

Always guard against empty or null data to avoid script errors that would cause the sandbox to suppress your output:

function onDataChange(widget, variables, actions, context) {
  const rows = widget.data?.rows ?? [];   // Safe empty fallback

  if (rows.length === 0) {
    variables.set('grandTotal', 0);
    return;
  }

  const total = rows.reduce((sum, r) => sum + (r.amount ?? 0), 0);
  variables.set('grandTotal', total);
}
widget.data is a snapshot widget.data is a read-only snapshot of the data at the time the event fired. Modifying it does not affect the widget's display. To influence what the widget shows, set app variables that the widget's data source params or token expressions bind to.