DataSet Forms
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.
| Approach | Where you wire loading | Best when |
|---|---|---|
onFormSubmit on the DataSet | DataSet definition (alongside form) | Default choice: Enter key, optional default OK button, one place for submit logic |
onClick on a form button | Inside form.buttons | Custom 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);
},
},Use the same Adaptable Form field types as elsewhere in AdapTable.
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);
},
},
],
},
},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.
The handler receives DataSetFormContext (formData, adaptableApi, and the selected dataSet). Call Grid API loadGridData when the user clicks the button.
Deep Dive
Understanding DataSetFormContext
- Two DataSets in
dataSetOptions.dataSets:JavaScript— usesloadDatawhen selected; loaded at start-up viasetDataSetin Adaptable Ready (short timeout so AdapTable is ready)TypeScript— opens a form;onFormSubmitfilters TypeScript rows by license, stars, and wiki flag, then calls Grid APIloadGridData
- See
adaptableOptions.tsandonAdaptableReady.tsin the demo tabs
- Switch between the two DataSets
- Change filters on the TypeScript form and submit to refresh rows