2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* VirtualScroller is a performant approach to handle huge data efficiently.
|
|
|
|
*
|
|
|
|
* [Live Demo](https://www.primevue.org/virtualscroller/)
|
|
|
|
*
|
|
|
|
* @module virtualscroller
|
|
|
|
*
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
import { VNode } from 'vue';
|
|
|
|
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Custom scroll index change event.
|
|
|
|
* @see scroll-index-change
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
export interface VirtualScrollerScrollIndexChangeEvent {
|
|
|
|
/**
|
|
|
|
* First index of the new data range to be loaded.
|
|
|
|
*/
|
|
|
|
first: number;
|
|
|
|
/**
|
|
|
|
* Last index of the new data range to be loaded.
|
|
|
|
*/
|
|
|
|
last: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-01 12:46:56 +00:00
|
|
|
* Custom lazy event.
|
|
|
|
* @see scroll-index-change
|
2022-09-06 12:03:37 +00:00
|
|
|
* @extends VirtualScrollerScrollIndexChangeEvent
|
|
|
|
*/
|
2022-09-14 11:26:01 +00:00
|
|
|
export interface VirtualScrollerLazyEvent extends VirtualScrollerScrollIndexChangeEvent {}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-01 12:46:56 +00:00
|
|
|
* Custom virtualscroller viewport metadata.
|
|
|
|
* @see scroll-index-change
|
2022-09-06 12:03:37 +00:00
|
|
|
* @extends VirtualScrollerScrollIndexChangeEvent
|
|
|
|
*/
|
2022-09-14 11:26:01 +00:00
|
|
|
export interface VirtualScrollerViewport extends VirtualScrollerScrollIndexChangeEvent {}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Virtual scroller rendered range.
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
export interface VirtualScrollerRangeMethod {
|
|
|
|
/**
|
|
|
|
* Whether the item is first.
|
|
|
|
*/
|
|
|
|
first: number;
|
|
|
|
/**
|
|
|
|
* Whether the item is last.
|
|
|
|
*/
|
|
|
|
last: number;
|
|
|
|
/**
|
|
|
|
* Viewport info.
|
|
|
|
* @see VirtualScrollerViewport
|
|
|
|
*/
|
|
|
|
viewport: VirtualScrollerViewport;
|
|
|
|
}
|
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Custom item options.
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
export interface VirtualScrollerItemOptions {
|
|
|
|
/**
|
|
|
|
* Item index
|
|
|
|
*/
|
|
|
|
index: number;
|
|
|
|
/**
|
|
|
|
* Items count
|
|
|
|
*/
|
|
|
|
count: number;
|
|
|
|
/**
|
|
|
|
* Whether the item is first.
|
|
|
|
*/
|
|
|
|
first: boolean;
|
|
|
|
/**
|
|
|
|
* Whether the item is last.
|
|
|
|
*/
|
|
|
|
last: boolean;
|
|
|
|
/**
|
|
|
|
* Whether the item is even.
|
|
|
|
*/
|
|
|
|
even: boolean;
|
|
|
|
/**
|
|
|
|
* Whether the item is odd.
|
|
|
|
*/
|
|
|
|
odd: boolean;
|
|
|
|
/**
|
|
|
|
* Optional
|
|
|
|
*/
|
|
|
|
[key: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-01 12:46:56 +00:00
|
|
|
* Custom virtualscroller loader options
|
|
|
|
* @see VirtualScrollerItemOptions
|
2022-09-06 12:03:37 +00:00
|
|
|
* @extends VirtualScrollerItemOptions
|
|
|
|
*/
|
2022-09-14 11:26:01 +00:00
|
|
|
export interface VirtualScrollerLoaderOptions extends VirtualScrollerItemOptions {}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Defines valid properties in VirtualScroller component.
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
export interface VirtualScrollerProps {
|
|
|
|
/**
|
|
|
|
* Unique identifier of the element.
|
|
|
|
*/
|
|
|
|
id?: string | undefined;
|
|
|
|
/**
|
|
|
|
* Inline style of the component.
|
|
|
|
*/
|
|
|
|
style?: any;
|
|
|
|
/**
|
|
|
|
* Style class of the component.
|
|
|
|
*/
|
|
|
|
class?: any;
|
|
|
|
/**
|
|
|
|
* An array of objects to display.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
items?: any[] | any[][] | undefined | null;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* The height/width of item according to orientation.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
itemSize?: number | number[] | undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Height of the scroll viewport.
|
|
|
|
*/
|
|
|
|
scrollHeight?: string | undefined;
|
|
|
|
/**
|
|
|
|
* Width of the scroll viewport.
|
|
|
|
*/
|
|
|
|
scrollWidth?: string | undefined;
|
|
|
|
/**
|
|
|
|
* The orientation of scrollbar.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue vertical
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
orientation?: 'vertical' | 'horizontal' | 'both' | undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Determines how many additional elements to add to the DOM outside of the view.
|
|
|
|
* According to the scrolls made up and down, extra items are added in a certain algorithm in the form of multiples of this number.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue half the number of items shown in the view.
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
numToleratedItems?: number | undefined;
|
|
|
|
/**
|
|
|
|
* Delay in scroll before new data is loaded.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue 0
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
delay?: number | undefined;
|
2023-02-28 10:33:00 +00:00
|
|
|
/**
|
|
|
|
* Delay after window's resize finishes.
|
|
|
|
* @defaultValue 10
|
|
|
|
*/
|
|
|
|
resizeDelay?: number | undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Defines if data is loaded and interacted with in lazy manner.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue false
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
lazy?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* If disabled, the VirtualScroller feature is eliminated and the content is displayed directly.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue false
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
disabled?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Used to implement a custom loader instead of using the loader feature in the VirtualScroller.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue false
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
loaderDisabled?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Whether to show loader.
|
|
|
|
*/
|
|
|
|
showLoader?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Used to implement a custom spacer instead of using the spacer feature in the VirtualScroller.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue true
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
showSpacer?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Whether to load items.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue false
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
loading?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Callback to invoke in lazy mode to load new data.
|
|
|
|
* @param {VirtualScrollerLazyEvent} event - Custom lazy event.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
onLazyLoad?(event: VirtualScrollerLazyEvent): void;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Index of the element in tabbing order.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @defaultValue 0.
|
2022-09-06 12:03:37 +00:00
|
|
|
*/
|
|
|
|
tabindex?: number | string | undefined;
|
2023-02-28 10:33:00 +00:00
|
|
|
/**
|
|
|
|
* When enabled, positions the content as inline.
|
|
|
|
* @defaultValue false
|
|
|
|
*/
|
|
|
|
inline?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Used to specify how many items to load in each load method in lazy mode.
|
|
|
|
* @defaultValue 0
|
|
|
|
*/
|
|
|
|
step?: number | undefined;
|
|
|
|
/**
|
|
|
|
* Used to append each loaded item to top without removing any items from the DOM. Using very large data may cause the browser to crash.
|
|
|
|
* @defaultValue false
|
|
|
|
*/
|
|
|
|
appendOnly?: boolean | undefined;
|
|
|
|
/**
|
|
|
|
* Whether to dynamically change the height or width of scrollable container.
|
|
|
|
* @defaultValue false
|
|
|
|
*/
|
|
|
|
autoSize?: boolean | undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Defines valid slots in VirtualScroller component.
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
export interface VirtualScrollerSlots {
|
|
|
|
/**
|
|
|
|
* Custom content template.
|
|
|
|
* @param {Object} scope - content slot's params.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
content(scope: {
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* An array of objects to display for virtualscroller
|
|
|
|
*/
|
|
|
|
items: any;
|
|
|
|
/**
|
|
|
|
* Style class of the content
|
|
|
|
*/
|
|
|
|
styleClass: string;
|
|
|
|
/**
|
|
|
|
* Referance of the content
|
|
|
|
* @param {HTMLElement} el - Element of 'ref' property
|
|
|
|
*/
|
|
|
|
contentRef(el: any): void;
|
|
|
|
/**
|
|
|
|
* Options of the items
|
|
|
|
* @param {number} index - Rendered index
|
|
|
|
* @return {@link VirtualScroller.VirtualScrollerItemOptions}
|
|
|
|
*/
|
|
|
|
getItemOptions(index: number): VirtualScrollerItemOptions;
|
|
|
|
/**
|
|
|
|
* Whether the data is loaded.
|
|
|
|
*/
|
|
|
|
loading: boolean;
|
|
|
|
/**
|
|
|
|
* Loader options of the items while the data is loading.
|
|
|
|
* @param {number} index - Rendered index
|
|
|
|
* @param {*} [ext] - Extra options
|
|
|
|
*/
|
|
|
|
getLoaderOptions(index: number, ext?: any): VirtualScrollerLoaderOptions;
|
|
|
|
/**
|
|
|
|
* The height/width of item according to orientation.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
itemSize: number | number[] | undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* The number of the rendered rows.
|
|
|
|
*/
|
|
|
|
rows: number | undefined;
|
|
|
|
/**
|
|
|
|
* The number of the rendered columns.
|
|
|
|
*/
|
|
|
|
columns: number | undefined;
|
|
|
|
/**
|
|
|
|
* The style of spacer element.
|
|
|
|
*/
|
|
|
|
spacerStyle: any;
|
|
|
|
/**
|
|
|
|
* The style of content element.
|
|
|
|
*/
|
|
|
|
contentStyle: any;
|
|
|
|
/**
|
|
|
|
* Whether the orientation is vertical.
|
|
|
|
*/
|
|
|
|
vertical: boolean;
|
|
|
|
/**
|
|
|
|
* Whether the orientation is horizontal.
|
|
|
|
*/
|
|
|
|
horizontal: boolean;
|
|
|
|
/**
|
|
|
|
* Whether the orientation is both.
|
|
|
|
*/
|
|
|
|
both: boolean;
|
2023-03-01 12:46:56 +00:00
|
|
|
}): VNode[];
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Custom item template.
|
|
|
|
* @param {Object} scope - item slot's params.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
item(scope: {
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Item data.
|
|
|
|
*/
|
|
|
|
item: any;
|
|
|
|
/**
|
|
|
|
* Item options.
|
|
|
|
*/
|
|
|
|
options: VirtualScrollerItemOptions;
|
2023-03-01 12:46:56 +00:00
|
|
|
}): VNode[];
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Custom loader template.
|
|
|
|
* @param {Object} scope - header slot's params.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
loader(scope: {
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Loader options.
|
|
|
|
*/
|
|
|
|
options: VirtualScrollerLoaderOptions;
|
2023-03-01 12:46:56 +00:00
|
|
|
}): VNode[];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* Defines valid emits in VirtualScroller component.
|
|
|
|
*/
|
|
|
|
export interface VirtualScrollerEmits {
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Emitted when the numToleratedItems changes.
|
|
|
|
* @param {number} value - New number tolerated items
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
'update:numToleratedItems'(value: number): void;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke when scroll position changes.
|
|
|
|
* @param {Event} event - Browser event.
|
2022-09-14 11:26:01 +00:00
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
scroll(event: Event): void;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke when scroll position and item's range in view changes.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @param {VirtualScrollerScrollIndexChangeEvent} event - Custom tab open event.
|
2022-09-14 11:26:01 +00:00
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
'scroll-index-change'(event: VirtualScrollerScrollIndexChangeEvent): void;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke in lazy mode to load new data.
|
|
|
|
* @param {VirtualScrollerLazyEvent} event - Custom lazy event.
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
'lazy-load'(event: VirtualScrollerLazyEvent): void;
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2023-03-01 12:46:56 +00:00
|
|
|
/**
|
|
|
|
* **PrimeVue - VirtualScroller**
|
|
|
|
*
|
|
|
|
* _VirtualScroller is a performant approach to handle huge data efficiently._
|
|
|
|
*
|
|
|
|
* [Live Demo](https://www.primevue.org/virtualscroller/)
|
|
|
|
* --- ---
|
|
|
|
* ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png)
|
|
|
|
*
|
|
|
|
* @group Component
|
|
|
|
*/
|
2022-09-06 12:03:37 +00:00
|
|
|
declare class VirtualScroller extends ClassComponent<VirtualScrollerProps, VirtualScrollerSlots, VirtualScrollerEmits> {
|
|
|
|
/**
|
|
|
|
* Scroll to move to a specific position.
|
|
|
|
* @param {ScrollToOptions} [options] - scoll options.
|
|
|
|
*/
|
|
|
|
scrollTo(options?: ScrollToOptions): void;
|
|
|
|
/**
|
|
|
|
* Scroll to move to a specific item.
|
|
|
|
* @param {number} index - Index of item according to orientation mode.
|
|
|
|
* @param {ScrollBehavior} [behavior] - Behavior of scroll.
|
|
|
|
*/
|
|
|
|
scrollToIndex(index: number, behavior?: ScrollBehavior): void;
|
|
|
|
/**
|
|
|
|
* It is used to move the specified index into the view. It is a method that will usually be needed when keyboard support is added to the virtualScroller component.
|
|
|
|
* @param {number} index - Index of item according to orientation mode.
|
2023-03-01 12:46:56 +00:00
|
|
|
* @param {'to-start' | 'to-end' } to - Defines the location of the item in view,
|
2022-09-06 12:03:37 +00:00
|
|
|
* @param {ScrollBehavior} [behavior] Behavior of scroll
|
|
|
|
*/
|
2023-03-01 12:46:56 +00:00
|
|
|
scrollInView(index: number, to: 'to-start' | 'to-end', behavior?: ScrollBehavior): void;
|
2022-09-06 12:03:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the range of items added to the DOM.
|
|
|
|
*/
|
|
|
|
getRenderedRange(): VirtualScrollerRangeMethod;
|
|
|
|
}
|
|
|
|
|
|
|
|
declare module '@vue/runtime-core' {
|
|
|
|
interface GlobalComponents {
|
2022-09-14 11:26:01 +00:00
|
|
|
VirtualScroller: GlobalComponentConstructor<VirtualScroller>;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VirtualScroller;
|