← Back to Stormify Documentation

PagedListBase

Abstract base class for PagedList — contains the full column-based paginated-list implementation. Users do not instantiate this directly; use the platform-specific PagedList subclass instead (it provides language-idiomatic constructors for Kotlin and Java).

A PagedList implements kotlin.collections.AbstractList, so it behaves as a normal List<T> while loading pages on demand from the database. Filtering and sorting are defined through Column objects set up at configuration time.

The Stormify instance is not passed at construction. It is resolved lazily on first access via (in order):

  1. The instance explicitly attached via Stormify.attach

  2. The registered Stormify.defaultInstance

If neither is available when the list first needs to touch the database, an error is thrown.

Usage

val list = PagedList<Company>()        // no stormify yet
stormify.attach(list) // binds the instance
list.addColumn("name") // text filter + sort
list.addColumn("contactPerson.firstName",
"contactPerson.lastName") // OR filter via FK
list.addRawColumn("SUM(amount)", Column.NUMERIC)

list.getColumn(0).filter = "Acme"
list.getColumn(1).sort = Column.ASCENDING

val company = list[0] // triggers page load
val total = list.size // triggers COUNT query

Parameters

classType

The KClass of the entity type

Type Parameters

T

The entity type

Inheritors

PagedList

Properties

Link copied to clipboard
Link copied to clipboard

The columns defined on this list. Columns are added via addColumn or addRawColumn and define what can be filtered and sorted.

Link copied to clipboard

Input parser for this list. Overrides defaultInputParser.

Link copied to clipboard

Whether the query should return only distinct results.

Link copied to clipboard

The page size — the number of elements loaded into memory at a time. Default is 15.

Link copied to clipboard
var selected: T?

Sets the selected entity, which will appear first in the list.

Link copied to clipboard
open override val size: Int

Total number of rows that match the current filters and constraints. The first access issues a COUNT(*) (or COUNT(DISTINCT ...) if isDistinct) query and caches the result for reuse.

Functions

Link copied to clipboard
fun add(entity: T)

Marks entity as selected so it appears first in the list. Call this after creating the entity via Stormify.

Link copied to clipboard
fun addColumn(vararg fieldPaths: String): Column

Adds a column with one or more field paths. The column type is auto-detected from the field's Kotlin type. Multiple paths use OR logic for filtering.

fun addColumn(vararg paths: ScalarPath): Column

Adds a column using type-safe KSP-generated path objects.

fun addColumn(enumValues: Map<String, Any>, vararg fieldPaths: String): Column

Adds an ENUM column with a custom display-name-to-DB-value map. Use this when the field is not a Kotlin enum but logically represents one (e.g., a status integer column with human-readable labels), or to override the auto-built map for a real enum field. The Map first argument distinguishes this overload from the scalar-typed variants at compile time.

fun addColumn(enumValues: Map<String, Any>, vararg paths: ScalarPath): Column

Enum-column variant using typed paths — same rules as the Map + String overload.

fun addColumn(type: Column.Type, vararg fieldPaths: String): Column

Adds a column with an explicit type override. Use this when the auto-detected type (based on the field's Kotlin type) is not what you want — for example, to treat a string zip-code column as numeric.

fun addColumn(type: Column.Type, vararg paths: ScalarPath): Column

Explicit-type variant of addColumn using typed paths.

Link copied to clipboard
fun addRawColumn(expression: String, type: Column.Type = Column.Type.TEXT): Column

Adds a raw/custom column backed by an arbitrary SQL expression.

fun addRawColumn(expression: String, type: Column.Type, sqlGenerator: SqlGenerator): Column

Adds a raw/custom column with a custom SQL generator. The sqlGenerator receives the column expression and the user's filter value, and returns a SQL fragment while staging bind parameters via SqlArgsCollector.

Link copied to clipboard
open override fun attachTo(stormify: Stormify)

Binds stormify to this object. Implementations store the reference and may reset any state that depends on the previously-attached instance.

Link copied to clipboard
fun forEachStreaming(action: (T) -> Unit)

Streams every row matching the current filter / sort / constraint state through action via a cursor — a single query that does not materialize the full result set. Use this for exports or bulk processing where paginating through the list's index-based iterator() would issue N / pageSize queries.

Link copied to clipboard
open operator override fun get(index: Int): T

Returns the row at index. If the row is not in the currently cached page, a new page is loaded around that index. Out-of-range indices propagate the underlying IndexOutOfBoundsException from the loaded page.

Link copied to clipboard

Returns a new PagedAggregator bound to this list. Each call returns a fresh aggregator so users can build multiple independent aggregation chains without interference.

Link copied to clipboard
fun getColumn(index: Int): Column

Returns the column at the given index.

Link copied to clipboard
open override fun indexOf(element: T): Int

Searches for the element in the currently cached page. Returns the absolute index, or -1 if not found in the current page.

Link copied to clipboard
fun refresh()

Forces the list to re-query the database on its next access.

Link copied to clipboard
fun remove(entity: T)

Clears the current selected entity. Call this after deleting the entity via Stormify.

Link copied to clipboard
fun reset()

Clears all column filters and sorting. Constraints are NOT cleared.

Link copied to clipboard

Re-applies a previously captured PagedListState. Keys present in state but missing from the current column set are silently ignored (the list's columns may have changed since the state was saved). Sort entries whose value is neither PagedListSort.ASC nor PagedListSort.DESC are treated as absent.

Link copied to clipboard

Captures the per-column filters / sorts / case-sensitivity flags plus the pageSize and isDistinct flag into a PagedListState. Intended for persisting a grid / picker screen's user state across navigation.

Link copied to clipboard
operator fun set(index: Int, element: T): T

Replaces the element at the given index in the cached page. This does NOT update the database — it only affects the in-memory view. The index must be within the currently loaded page.

Link copied to clipboard
fun setConstraints(query: String, vararg args: Any)

Sets a fixed constraint (WHERE clause) for this list. This constraint is always applied in addition to any column filters.