Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ActiveDataProvider

ActiveDataProvider implements a data provider based on db queries.

ActiveDataProvider provides real time data by performing DB queries using query.

The following is an example of using ActiveDataProvider to provide ActiveRecord instances:

let provider = new ActiveDataProvider({
modelClass: Post,
query: { where: { companyId: 123 } },
pagination: {
pageSize: 20,
},
});

// get the posts in the current page
let posts = provider.getModels();

For more details and usage information on ActiveDataProvider, see the guide article on data providers.

author

Mahesh S Warrier https://github.com/codespede

Hierarchy

Index

Constructors

Properties

id: string

An ID that uniquely identifies the data provider among all data providers. Generated automatically the following way in case it is not set:

  • First data provider ID is empty.
  • Second and all subsequent data provider IDs are: "dp-1", "dp-2", etc.
initialization: Promise<void>

A Promise which resolves when this Component has been successfully initialized.

key: string

The column that is used as the key of the data models. This can be a column name that returns the key value of a given data model.

If this is not set, the primary keys of modelClass will be used.

see

getKeys

modelClass: Model

Model Class which can be used for resolving Attribute Labels, Hints etc.

ormAdapter: any

Th adapter for the ORM which is being used for the Application. eg:- SequelizeAdapter

query: {} = {}

the query that is used to fetch data models and totalCount if it is not explicitly set. This structure of this property depends upon the ORM being used. Example for Sequelize: let provider = new ActiveDataProvider({ modelClass: Post, query: { where: { companyId: 123 createdDate: {[Op.lte]: Date.now() //createdDate less than or equal to now. } } }); provider.getModels(); // returns the models matching the current query.

Type declaration

  • [key: string]: any
totalCountPromise: Promise<number>

Promise which resolves to the number matching records for the current query.

Methods

  • getCount(): number
  • getKeys(): void | string[]
  • Returns the key values associated with the data models.

    Returns void | string[]

    the list of key values corresponding to [[models]]. Each data model in [[models]] is uniquely identified by the corresponding key value in this array.

  • getModels(): Promise<Model[]>
  • getPagination(): any
  • getSort(): any
  • getTotalCount(): Promise<number>
  • init(): Promise<void>
  • prepare(forcePrepare?: boolean): Promise<void>
  • Prepares the data models and keys.

    This method will prepare the data models and keys that can be retrieved via getModels and getKeys.

    This method will be implicitly called by getModels and getKeys if it has not been called before.

    Parameters

    • forcePrepare: boolean = false

      whether to force data preparation even if it has been done before.

    Returns Promise<void>

  • prepareKeys(models: any): any[]
  • prepareModels(): Promise<any>
  • prepareTotalCount(): Promise<any>
  • refresh(): void
  • setModels(models: Model[]): void
  • setPagination(value: any): void
  • Sets the pagination for this data provider.

    Parameters

    • value: any

      the pagination to be used by this data provider. This can be one of the following:

      • a configuration array for creating the pagination object. The "class" element defaults to Pagination
      • an instance of Pagination or its subclass
      • false, if pagination needs to be disabled.

    Returns void

  • setSort(value: any): void
  • setTotalCount(value: number): void

Generated using TypeDoc