/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { CompositeFilterDescriptor, GroupDescriptor, SortDescriptor } from '@progress/kendo-data-query'; /** * Describes the options for configuring the useDataSource hook. * * @template T - The type of data items in the data source. Defaults to any. */ export type DataSourceProps = { /** * The total number of records in the data source. */ total?: number; /** * The initial total number of records in the data source. */ defaultTotal?: number; /** * The current data array to be managed by the hook. * This represents the data items that are currently available in the data source. * If not provided, the `defaultData` will be used as the initial value. */ data?: T[]; /** * The initial data array to be managed by the hook. */ defaultData?: T[]; /** * The current sorting configuration. */ sort?: SortDescriptor[]; /** * The initial sorting configuration. */ defaultSort?: SortDescriptor[]; /** * The current filter configuration. */ filter?: CompositeFilterDescriptor; /** * The initial filter configuration. */ defaultFilter?: CompositeFilterDescriptor; /** * The current number of records to skip (for paging). */ skip?: number; /** * The initial number of records to skip (for paging). */ defaultSkip?: number; /** * The current number of records to take per page. */ take?: number; /** * The initial number of records to take per page. */ defaultTake?: number; /** * The current grouping configuration. */ group?: GroupDescriptor[]; /** * The initial grouping configuration. */ defaultGroup?: GroupDescriptor[]; /** * Specifies whether filtering is enabled. * * @default true */ filterable?: boolean; /** * Specifies whether sorting is enabled. * * @default true */ sortable?: boolean; /** * Specifies whether paging is enabled. * * @default true */ pageable?: boolean; /** * Specifies whether grouping is enabled. * * @default true */ groupable?: boolean; /** * Configuration for the data schema, including model definition. */ schema: { model: { /** * The field that serves as the unique identifier for records. */ id: string; }; }; }; /** * Represents a data source with data presentation operations (filtering, sorting, paging, grouping). * * @template T - The type of data items in the data source. Defaults to any. */ export type DataSource = { /** The array of data items. */ data: T[]; /** * Sets the data items in the data source. * * @param value - The array of new data items. */ setData: (value: T[]) => void; /** The total number of data items. */ total: number; /** The schema used for data validation and transformation. */ schema: DataSourceProps['schema']; /** The current sort descriptors applied to the data. */ sort: SortDescriptor[] | undefined; /** * Sets the sort descriptors for the data. * * @param value - The new sort descriptors. */ setSort: (value: SortDescriptor[] | undefined) => void; /** The current filter descriptor applied to the data. */ filter: CompositeFilterDescriptor | undefined; /** * Sets the filter descriptor for the data. * * @param value - The new filter descriptor. */ setFilter: (value: CompositeFilterDescriptor | undefined) => void; /** The current skip value for pagination. */ skip: number | undefined; /** * Sets the skip value for pagination. * * @param value - The new skip value. */ setSkip: (value: number | undefined) => void; /** The current take value for pagination. */ take: number | undefined; /** * Sets the take value for pagination. * * @param value - The new take value. */ setTake: (value: number | undefined) => void; /** The current group descriptors applied to the data. */ group: GroupDescriptor[] | undefined; /** * Sets the group descriptors for the data. * * @param value - The new group descriptors. */ setGroup: (value: GroupDescriptor[] | undefined) => void; /** The current data state, including sorting, filtering, and pagination. */ dataState: Partial>; /** * Sets the data state, including sorting, filtering, and pagination. * * @param dataState - The new data state. */ setDataState: (dataState: Partial>) => void; /** * Sets the total number of data items. * * @param value - The new total value. */ setTotal: (value: number | undefined) => void; }; /** * A hook that provides functionality for managing local data with built-in support for filtering, sorting, paging, and grouping. * * @template T - The type of data items in the data source. Defaults to any. * @param {DataSourceProps} props - The configuration options for the data source. * @returns {DataSource} An object containing data management methods and properties. * * @example * ```tsx * interface Product { * ProductID: number; * ProductName: string; * UnitPrice: number; * } * * const dataSource = useDataSource({ * defaultData: products, * defaultSort: [{ field: 'UnitPrice', dir: 'desc' }], * defaultSkip: 0, * take: 10, * schema: { * model: { * id: 'ProductID' * } * } * }); * * return ( * { * dataSource.setDataState(event.dataState); * }} * > * * * * ); * ``` */ export declare const useDataSource: (props: DataSourceProps) => DataSource;