DataSet Forms

View as Markdown

Summary

  • DataSets are defined in Adaptable Options
  • A DataSet can include a Form so users choose parameters before data is loaded

DataSets can optionally include Form definitions so users can narrow what data is returned.

When a DataSet with a form is selected, AdapTable displays an Adaptable Form.

Handling Form Submission

Unlike DataSets without a form, AdapTable does not fire the DataSet Selected Event when the user selects a DataSet that defines a form.

After the user fills in the form, you load row data into the Grid.

There are two equivalent ways to hook that moment — pick one per DataSet; you do not need both.

ApproachWhere you wire loadingBest when
onFormSubmit on the DataSetDataSet definition (alongside form)Default choice: Enter key, optional default OK button, one place for submit logic
onClick on a form buttonInside form.buttonsCustom button labels, multiple actions, or legacy setups that already use form buttons

Both handlers receive the same DataSetFormContext and usually call Grid API loadGridData.

onFormSubmit on the DataSet

Define onFormSubmit on the DataSet object.

If you omit form.buttons, AdapTable adds a default OK button that submits the form and calls your handler.

Developer Guide

Submitting a DataSet Form with onFormSubmit

{
  name: 'TypeScript',
  description: 'TypeScript Frameworks',
  form: {
    fields: [
      { name: 'minStars', label: 'Minimum Stars', fieldType: 'number', defaultValue: 10000 },
    ],
  },
  onFormSubmit: (context: DataSetFormContext) => {
    const rows = rowData.filter(
      r => r.language === 'TypeScript' && r.github_stars > context.formData.minStars
    );
    context.adaptableApi.gridApi.loadGridData(rows);
  },
},
1
Define form fields on the DataSet

Use the same Adaptable Form field types as elsewhere in AdapTable.

2
Implement onFormSubmit

AdapTable invokes this when the user presses Enter or clicks a form button (including a default OK button when you omit buttons). Use context.formData and context.adaptableApi.gridApi.loadGridData.

onClick on a form button

The second option is to define form.buttons and load data in a button's onClick.

Use this instead of onFormSubmit when you want explicit buttons (for example Load and Cancel) or when submit logic already lives on a button handler.

Hint

  • If the DataSet also defines onFormSubmit, AdapTable still invokes it when a button submits the form
  • Avoid duplicating the same load logic in both places
Developer Guide

Using a custom form button onClick

{
  name: 'TypeScript',
  description: 'TypeScript Frameworks',
  form: {
    fields: [
      { name: 'minStars', label: 'Minimum Stars', fieldType: 'number', defaultValue: 10000 },
    ],
    buttons: [
      {
        label: 'Load',
        onClick: (_button, context: DataSetFormContext) => {
          const rows = rowData.filter(
            r =>
              r.language === 'TypeScript' &&
              r.github_stars > (context.formData?.minStars as number)
          );
          context.adaptableApi.gridApi.loadGridData(rows);
        },
      },
    ],
  },
},
1
Add a submit button to the form

Define one or more entries in form.buttons. Use this when you need custom labels, multiple actions, or you are not using onFormSubmit on the DataSet.

2
Load data in the button onClick handler

The handler receives DataSetFormContext (formData, adaptableApi, and the selected dataSet). Call Grid API loadGridData when the user clicks the button.

Deep Dive

Understanding DataSetFormContext

Using DataSet Forms
Fork
  • Two DataSets in dataSetOptions.dataSets:
    • JavaScript — uses loadData when selected; loaded at start-up via setDataSet in Adaptable Ready (short timeout so AdapTable is ready)
    • TypeScript — opens a form; onFormSubmit filters TypeScript rows by license, stars, and wiki flag, then calls Grid API loadGridData
  • See adaptableOptions.ts and onAdaptableReady.ts in the demo tabs
Try It Out
  • Switch between the two DataSets
  • Change filters on the TypeScript form and submit to refresh rows
Loading demo…