Forest Admin - API reference
    Preparing search index...

    Type Parameters

    Index

    Constructors

    Properties

    addField: (
        name: string,
        definition: ComputedDefinition<S, N>,
    ) => CollectionCustomizer<S, N> = ...

    Add a new field on the collection.

    Type Declaration

    .addField('fullName', {
    columnType: 'String',
    dependencies: ['firstName', 'lastName'],
    getValues: (records) => records.map(record => `${record.lastName} ${record.firstName}`),
    });
    name: string

    Accessors

    Methods

    • Add a new action on the collection.

      Parameters

      • name: string

        the name of the action

      • definition: ActionDefinition<S, N>

        the definition of the action

      Returns this

      .addAction('is live', {
      scope: 'Single',
      execute: async (context, resultBuilder) => {
      return resultBuilder.success('Is live!');
      },
      })
    • Create a new API chart

      Parameters

      • name: string

        name of the chart

      • definition: CollectionChartDefinition<S, N>

        definition of the chart

      Returns this

      .addChart('numCustomers', (context, resultBuilder) => {
      return resultBuilder.distribution({
      tomatoes: 10,
      potatoes: 20,
      carrots: 30,
      });
      })
    • Add a virtual collection into the related data of a record.

      Parameters

      Returns this

      .addExternalRelation('states', {
      schema: { code: 'Number', name: 'String' },
      listRecords: ({ id }) => {
      return record.id == 34 ?
      [{ code: 'AL', name: 'Alabama' }, { code: 'AK', name: 'Alaska' }] :
      [{ code: 'AZ', name: 'Arizona' }, { code: 'TX', name: 'Texas' }];
      }
      })
    • Add a new validator to the edition form of a given field

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        The name of the field

      • operator:
            | "Equal"
            | "NotEqual"
            | "LessThan"
            | "GreaterThan"
            | "LessThanOrEqual"
            | "GreaterThanOrEqual"
            | "Match"
            | "NotContains"
            | "NotIContains"
            | "LongerThan"
            | "ShorterThan"
            | "IncludesAll"
            | "IncludesNone"
            | "Today"
            | "Yesterday"
            | "PreviousMonth"
            | "PreviousQuarter"
            | "PreviousWeek"
            | "PreviousYear"
            | "PreviousMonthToDate"
            | "PreviousQuarterToDate"
            | "PreviousWeekToDate"
            | "PreviousXDaysToDate"
            | "PreviousXDays"
            | "PreviousYearToDate"
            | "Present"
            | "Blank"
            | "Missing"
            | "In"
            | "NotIn"
            | "StartsWith"
            | "EndsWith"
            | "Contains"
            | "IStartsWith"
            | "IEndsWith"
            | "IContains"
            | "Like"
            | "ILike"
            | "Before"
            | "After"
            | "AfterXHoursAgo"
            | "BeforeXHoursAgo"
            | "Future"
            | "Past"

        The validator that you wish to add

      • Optionalvalue: unknown

        A configuration value that the validator may need

      Returns this

      .addFieldValidation('firstName', 'LongerThan', 2);
      
    • Add a many to many relation to the collection

      Type Parameters

      • Foreign extends string
      • Through extends string

      Parameters

      • name: string

        name of the new relation

      • foreignCollection: Foreign

        name of the targeted collection

      • throughCollection: Through

        name of the intermediary collection

      • options: {
            foreignKey: Extract<keyof S[Through]["plain"], string>;
            foreignKeyTarget?: Extract<keyof S[Foreign]["plain"], string>;
            originKey: Extract<keyof S[Through]["plain"], string>;
            originKeyTarget?: Extract<keyof S[N]["plain"], string>;
        }

        extra information about the relation

      Returns this

      dvds.addManyToManyRelation('rentalsOfThisDvd', 'rentals', 'dvdRentals', {
      originKey: 'dvdId',
      foreignKey: 'rentalId'
      })
    • Add a many to one relation to the collection

      Type Parameters

      • T extends string

      Parameters

      • name: string

        name of the new relation

      • foreignCollection: T

        name of the targeted collection

      • options: {
            foreignKey: Extract<keyof S[N]["plain"], string>;
            foreignKeyTarget?: Extract<keyof S[T]["plain"], string>;
        }

        extra information about the relation

      Returns this

      books.addManyToOneRelation('myAuthor', 'persons', { foreignKey: 'authorId' })
      
    • Add a one to many relation to the collection

      Type Parameters

      • T extends string

      Parameters

      • name: string

        name of the new relation

      • foreignCollection: T

        name of the targeted collection

      • options: {
            originKey: Extract<keyof S[T]["plain"], string>;
            originKeyTarget?: Extract<keyof S[N]["plain"], string>;
        }

        extra information about the relation

      Returns this

      persons.addOneToManyRelation('writtenBooks', 'books', { originKey: 'authorId' })
      
    • Add a one to one relation to the collection

      Type Parameters

      • T extends string

      Parameters

      • name: string

        name of the new relation

      • foreignCollection: T

        name of the targeted collection

      • options: {
            originKey: Extract<keyof S[T]["plain"], string>;
            originKeyTarget?: Extract<keyof S[N]["plain"], string>;
        }

        extra information about the relation

      Returns this

      persons.addOneToOneRelation('bestFriend', 'persons', { originKey: 'bestFriendId' })
      
    • Add a new segment on the collection.

      Parameters

      • name: string

        the name of the segment

      • definition: SegmentDefinition<S, N>

        a function used to generate a condition tree or a condition tree

      Returns this

      .addSegment(
      'Wrote more than 2 books',
      { field: 'booksCount', operator: 'GreaterThan', value: 2 }
      );
    • Disable count in list view pagination for improved performance.

      Returns this

      .disableCount()
      
    • Disable sorting on a specific field.

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field with sorting to be disabled

      Returns this

      .disableFieldSorting('fullName');
      
    • Enable filtering on a specific field using emulation. As for all the emulation method, the field filtering will be done in-memory.

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field to enable emulation on

      Returns this

      .emulateFieldFiltering('aField');
      
    • Enable filtering on a specific field with a specific operator using emulation. As for all the emulation method, the field filtering will be done in-memory.

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field to enable emulation on

      • operator:
            | "Equal"
            | "NotEqual"
            | "LessThan"
            | "GreaterThan"
            | "LessThanOrEqual"
            | "GreaterThanOrEqual"
            | "Match"
            | "NotContains"
            | "NotIContains"
            | "LongerThan"
            | "ShorterThan"
            | "IncludesAll"
            | "IncludesNone"
            | "Today"
            | "Yesterday"
            | "PreviousMonth"
            | "PreviousQuarter"
            | "PreviousWeek"
            | "PreviousYear"
            | "PreviousMonthToDate"
            | "PreviousQuarterToDate"
            | "PreviousWeekToDate"
            | "PreviousXDaysToDate"
            | "PreviousXDays"
            | "PreviousYearToDate"
            | "Present"
            | "Blank"
            | "Missing"
            | "In"
            | "NotIn"
            | "StartsWith"
            | "EndsWith"
            | "Contains"
            | "IStartsWith"
            | "IEndsWith"
            | "IContains"
            | "Like"
            | "ILike"
            | "Before"
            | "After"
            | "AfterXHoursAgo"
            | "BeforeXHoursAgo"
            | "Future"
            | "Past"

        the operator to emulate

      Returns this

      .emulateFieldOperator('aField', 'In');
      
    • Enable sorting on a specific field using emulation. As for all the emulation method, the field sorting will be done in-memory.

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field to enable emulation on

      Returns this

      .emulateFieldSorting('fullName');
      
    • Import a field from a many to one or one to one relation.

      Parameters

      • name: string

        the name of the field that will be created on the collection

      • options: { path: TFieldName<S, N>; readonly?: boolean }

        options to import the field

      Returns this

      .importField('authorName', { path: 'author:fullName' })
      
    • Choose how binary data should be transported to the GUI. By default, all fields are transported as 'datauri', with the exception of primary and foreign keys.

      Using 'datauri' allows to use the FilePicker widget, while 'hex' is more suitable for short binary data (for instance binary uuids).

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field

      • binaryMode: BinaryMode

        either 'datauri' or 'hex'

      Returns this

      .replaceFieldBinaryMode('avatar', 'datauri');
      
    • Replace an implementation for a specific operator on a specific field. The operator replacement will be done by the datasource.

      Type Parameters

      • C extends string

      Parameters

      • name: C

        the name of the field to filter on

      • operator:
            | "Equal"
            | "NotEqual"
            | "LessThan"
            | "GreaterThan"
            | "LessThanOrEqual"
            | "GreaterThanOrEqual"
            | "Match"
            | "NotContains"
            | "NotIContains"
            | "LongerThan"
            | "ShorterThan"
            | "IncludesAll"
            | "IncludesNone"
            | "Today"
            | "Yesterday"
            | "PreviousMonth"
            | "PreviousQuarter"
            | "PreviousWeek"
            | "PreviousYear"
            | "PreviousMonthToDate"
            | "PreviousQuarterToDate"
            | "PreviousWeekToDate"
            | "PreviousXDaysToDate"
            | "PreviousXDays"
            | "PreviousYearToDate"
            | "Present"
            | "Blank"
            | "Missing"
            | "In"
            | "NotIn"
            | "StartsWith"
            | "EndsWith"
            | "Contains"
            | "IStartsWith"
            | "IEndsWith"
            | "IContains"
            | "Like"
            | "ILike"
            | "Before"
            | "After"
            | "AfterXHoursAgo"
            | "BeforeXHoursAgo"
            | "Future"
            | "Past"

        the operator to replace

      • replacer: OperatorDefinition<S, N, C>

        the proposed implementation

      Returns this

      .replaceFieldOperator('fullName', 'Contains', (value) => {
      return {
      aggregator: 'Or',
      conditions: [{
      field: 'firstName',
      operator: 'Contains',
      value
      }, {
      field: 'lastName',
      operator: 'Contains',
      value
      }]
      }
      });
    • Replace an implementation for the sorting. The field sorting will be done by the datasource.

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the field to enable sort

      • equivalentSort: TSortClause<S, N>[]

        the sort equivalent

      Returns this

      .replaceFieldSorting(
      'fullName',
      [
      { field: 'firstName', ascending: true },
      { field: 'lastName', ascending: true },
      ]
      )
    • Replace the write behavior of a field.

      Type Parameters

      • C extends string

      Parameters

      • name: C

        the name of the field

      • definition: WriteDefinition<S, N, C>

        the function or a value to represent the write behavior

      Returns this

      .replaceFieldWriting('fullName', fullName => {
      const [firstName, lastName] = fullName.split(' ');
      return { firstName, lastName };
      });
    • Mark a field as optional

      Be wary that your database might still refuse empty values if it requires one

      Parameters

      • name: Extract<keyof S[N]["plain"], string>

        the name of the column you would like optional

      Returns this

      .setFieldNullable('userName');