CngxRecycler
projects/common/data/recycler/recycler.ts
Referenced by#
Import#
import { CngxRecycler } from '@cngx/common/data'
Description#
Signal-based virtualizer returned by injectRecycler.
All derived values are computed() - the system cannot become inconsistent.
Index#
Instance Properties#
SignalReports the index of the item that had focus when it left the rendered range.
null when no focus was lost. Consumer can use this to restore focus.
SignalThe range of item indices that must be available for rendering. Use in an effect to trigger page loads for windowed/sparse data sources.
Unlike firstVisible/lastVisible (which exclude overscan), this includes
overscan items - all indices in this range may be rendered.
effect(() => {
const { start, end } = recycler.neededRange();
const startPage = Math.floor(start / PAGE_SIZE);
const endPage = Math.floor(end / PAGE_SIZE);
for (let p = startPage; p <= endPage; p++) {
if (!pageCache.has(p)) { loadPage(p); }
}
});SignalTarget index that scrollToIndex() is waiting for.
Non-null when the target index exceeds totalCount - consumer
can show a "Scrolling to item..." indicator or trigger page loads.
Clears automatically when totalCount grows past the target.
SignalPlaceholder count before rendered items. Only non-zero in grid mode.
SignalisLoading AND skeletonDelay elapsed. Prevents skeleton flicker on fast loads.
SignalHow many skeleton items fit in the viewport: ceil(clientHeight / estimateSize).
Methods#
anchorTo(index: number)Locks scroll position relative to an item. When items are inserted above
the anchored item, scrollTop is corrected to maintain visual position.
measure(index: number, element: HTMLElement)Reports a measured item height to the internal SizeCache. No-op in grid mode (uniform row height assumed). Prefer CngxMeasure directive over calling this directly.
HTMLElementscrollToIndex(index: number, behavior?: ScrollBehavior)Scrolls to a specific item index. When index >= totalCount, stores
the target in pendingTarget for resolution when data arrives.
ScrollBehaviorSignalsliced(items: Signal) Creates a computed() slicing items to the visible range.
Call once in a field initializer - each call creates a new computed node.
Do NOT call in templates or methods.
Signal