Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DataProvider

BaseDataProvider provides a base class for ActiveDataProvider and ArrayDataProvider

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

property-read

int $count The number of data models in the current page. This property is read-only.

property

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

property

array $models The list of data models in the current page.

property

Pagination|false $pagination The pagination object. If this is false, it means the pagination is disabled. Note that the type of this property differs in getter and setter. See [[getPagination()]] and [[setPagination()]] for details.

property

Sort|bool $sort The sorting object. If this is false, it means the sorting is disabled. Note that the type of this property differs in getter and setter. See [[getSort()]] and [[setSort()]] for details.

property

int $totalCount Total number of possible data models.

author

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

Hierarchy

Index

Constructors

Properties

_keys: void | string[] = []
_models: Model[] = []
_pagination: any
_sort: any
_totalCount: number
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.

modelClass: Model

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

totalCountPromise: Promise<number>

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

counter: number = 0

Number of data providers on the current page. Used to generate unique IDs.

Methods

  • getCount(): number
  • Returns the number of data models in the current page.

    Returns number

    the number of data models in the current page.

  • 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[]>
  • Returns the data models in the current page.

    Returns Promise<Model[]>

    the list of data models in the current page.

  • getPagination(): any
  • Returns the pagination object used by this data provider. Note that you should call prepare or getModels first to get correct values of Pagination.totalCount and [[Pagination::pageCount]].

    Returns any

    the pagination object. If this is false, it means the pagination is disabled.

  • getSort(): any
  • Returns the sorting object used by this data provider.

    Returns any

    the sorting object. If this is false, it means the sorting is disabled.

  • getTotalCount(): Promise<number>
  • init(): Promise<void>
  • Initializes the object. This method is invoked at the end of the constructor after the object is initialized with the given configuration.

    Returns 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: Model[]): void
  • Prepares the keys associated with the currently available data models.

    Parameters

    • models: Model[]

      the available data models

    Returns void

    the keys

  • prepareModels(): Promise<Model[]>
  • Prepares the data models that will be made available in the current page.

    Returns Promise<Model[]>

    the available data models

  • prepareTotalCount(): Promise<number>
  • Returns a value indicating the total number of data models in this data provider.

    Returns Promise<number>

    total number of data models in this data provider.

  • refresh(): void
  • setModels(models: Model[]): void
  • Sets the data models in the current page.

    Parameters

    • models: Model[]

      the models in the current page

    Returns 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
  • Sets the sort definition for this data provider.

    Parameters

    • value: any

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

      • a configuration array for creating the sort definition object. The "class" element defaults to 'yii\data\Sort'
      • an instance of Sort or its subclass
      • false, if sorting needs to be disabled.

    Returns void

  • setTotalCount(value: number): void
  • Sets the total number of data models.

    Parameters

    • value: number

      the total number of data models.

    Returns void

Generated using TypeDoc