Skip to content
Zonvoir Table LogoZonvoir Table

Column Persistence API Reference

Column Persistence allows user-customized column ordering to be stored in the database and applied automatically when rendering tables.


Zonvoir\InertiaTablePro\Concerns\HasColumnPersistence provides backend column ordering persistence for table classes.

Item Value
Trait Zonvoir\InertiaTablePro\Concerns\HasColumnPersistence
Included By Zonvoir\InertiaTablePro\Concerns\HasProFeatures
Used In Table definitions extending Zonvoir\InertiaTable\Table
persistsColumns()

Signature

public function persistsColumns(): bool

Determine whether column persistence is currently enabled on the table instance, based on instance configuration and global package settings.

withoutColumnPersistence()

Signature

public function withoutColumnPersistence(): static

Disable column persistence for this table instance.

withColumnPersistence()

Signature

public function withColumnPersistence(bool $enable = true): static

Explicitly enable or disable column persistence for this table instance.

persistenceIdentifier()

Signature

public function persistenceIdentifier(): string

Resolve the stable identifier used to look up and store user preferences. Explicitly named tables use that name; otherwise the core table name is used.

savedColumnOrder()

Signature

public function savedColumnOrder(): ?array

Retrieve the cached or persisted column order array for the current authenticated user.

resolvePersistenceUser()

Signature

protected function resolvePersistenceUser(): ?Authenticatable

Resolve the authenticatable user model against which preferences are stored. Defaults to auth()->user().

applyColumnOrder()

Signature

public function applyColumnOrder(array $columns, ?array $savedOrder = null): array

Reorder a list of column instances or column definitions based on saved column keys, preserving any newly introduced columns at the end.

columnsDefinition()

Signature

public function columnsDefinition(): array

Overrides the core table method to automatically apply the authenticated user's saved column order before returning column definitions.


Zonvoir\InertiaTablePro\Services\TablePreferenceService manages database preference records.

findForUser()

Signature

public function findForUser(?Authenticatable $user, string $tableName): ?TableUserPreference

Find the user preference record matching the user and table name. Returns null when no user is provided.

saveForUser()

Signature

public function saveForUser(Authenticatable $user, string $tableName, array $columns, ?array $settings = null): TableUserPreference

Create or update the preference record for the specified user and table name with the given column order.

resetForUser()

Signature

public function resetForUser(Authenticatable $user, string $tableName): bool

Delete the stored preference record for the user and table name.


Zonvoir\InertiaTablePro\Models\TableUserPreference is the Eloquent model representing stored user table preferences.

Attribute Type Description
id int Primary key
user_type ?string Polymorphic morph class of the authenticatable model
user_id ?string User identifier
table_name string Table identifier string
columns ?array JSON-casted array of column attribute strings
settings ?array JSON-casted additional preferences or view settings
created_at DateTime Record creation timestamp
updated_at DateTime Record modification timestamp

When persistence is enabled, the backend adds reorderable: true at the top level of the table payload and merges these values into meta:

{
"reorderable": true,
"meta": {
"reorderable": true,
"preferenceEndpoint": "/zonvoir-table/preferences",
"preferenceResetEndpoint": "/zonvoir-table/preferences"
}
}

Endpoint values are present when the corresponding named routes are registered.


Method Route name Default path Request body
POST zonvoir-table.preferences.store /zonvoir-table/preferences { "table": string, "columns": string[], "settings"?: object }
DELETE zonvoir-table.preferences.destroy /zonvoir-table/preferences { "table": string }

Both endpoints use the configured zonvoir-table.persistence.middleware stack plus AuthenticateTablePreferences. Unauthenticated requests return 401; invalid authenticated requests return 422.

Store validation limits the table name to 255 characters, the order to 100 column keys, each key to 255 characters, and optional settings to 50 entries.


useColumnPersistence is exported by @zonvoir/inertia-table-vue for interacting with the column persistence API.

export interface UseColumnPersistenceOptions {
table?: TableDefinition | TableResource;
tableName?: string;
endpoint?: string;
resetEndpoint?: string;
debounceMs?: number;
}
Option Type Default Description
table TableDefinition | TableResource undefined Table payload containing its name and optional metadata endpoints
tableName string '' Explicit table name override
endpoint string '/zonvoir-table/preferences' Endpoint for storing column preferences
resetEndpoint string '/zonvoir-table/preferences' Endpoint for deleting stored preferences
debounceMs number 300 Debounce duration in milliseconds before saving
export interface UseColumnPersistenceReturn {
isSaving: Ref<boolean>;
persistColumnOrder: (columns: Array<string | TableColumn>) => Promise<boolean>;
resetColumnOrder: () => Promise<boolean>;
}
Property Type Description
isSaving Ref<boolean> Reactive ref indicating whether an HTTP save or reset request is currently executing. Built-in components do not render this state.
persistColumnOrder (columns) => Promise<boolean> Debounced function to persist a new column ordering array to the server
resetColumnOrder () => Promise<boolean> Deletes the stored preference for this table and resolves true on success

The composable sends JSON with same-origin credentials. When Laravel’s XSRF-TOKEN cookie is available, it is decoded and forwarded through the X-XSRF-TOKEN header. Both methods return false for a missing table identifier, a network error, or a non-successful response.


Column reordering and persistence components are included directly in @zonvoir/inertia-table-vue. When a table definition has reordering enabled (reorderable: true from HasColumnPersistence or HasProFeatures), standard table components automatically activate drag-and-drop and persistence:

Supports interactive HTML5 drag-and-drop column reordering across header cells:

  • Props: columns, allColumns, sorting, sticky, stickyOffsets, stickySides, isColumnSticky, reorderable, tableApi, table
  • Emits: sort, stick, hide, reorder

Supports vertical 6-dot reordering handles and one-click reset to default order:

  • Props: columns, allColumns, isColumnVisible, reorderable, tableApi, table
  • Emits: toggle, reorder