Column Management
TableBuilder provides multiple ways to control which columns are displayed and in what order. This guide covers all available methods for managing table columns.
Quick Reference
| Method | Description | Scope | Use Case |
|---|---|---|---|
->hide() (RuleBuilder) |
Hide field from lists, forms and detail view | Model-level | Passwords, sensitive data |
->hideFromList() (RuleBuilder) |
Hide field only from list/table view | Model-level | Long text fields shown only in forms |
->resetFields() |
Hide all existing columns, start fresh | Table-level | Show only specific columns |
->field() / ->column() |
Define visible columns in order | Table-level | Control order and visibility |
->hide() (only TableBuilder) |
Hide specific column in this table | Table-level | Hide one or few columns |
->hideColumns() |
Hide multiple columns at once | Table-level | Hide several columns |
->moveBefore() |
Move current field before another | Table-level | Adjust single column position |
->reorderColumns() |
Completely reorder all columns (use at the end!) | Table-level | Full control of column order |
Model-Level Column Control (RuleBuilder)
In your Model's configure($rule) method, you can use RuleBuilder methods to control field visibility across the entire application.
1. Hide Field Completely
Use hide() in RuleBuilder to hide fields from lists, edit forms, and detail views.
class UserModel extends AbstractModel
{
protected function configure($rule): void
{
$rule->table('#__users')
->id()
->string('username', 100)
->string('password', 255)->hide() // Hidden everywhere
->email('email');
}
}
2. Hide From List Only
Use hideFromList() in RuleBuilder to hide fields from table views while keeping them available in forms.
class PostModel extends AbstractModel
{
protected function configure($rule): void
{
$rule->table('#__posts')
->id()
->string('title', 200)
->text('description')->hideFromList() // Hidden from tables only
->text('content')->hideFromList() // Hidden from tables only
->datetime('created_at');
}
}
// These fields won't appear in tables but are available in forms
3. Other RuleBuilder Visibility Methods
protected function configure($rule): void
{
$rule->table('#__posts')
->id()
// Hide from edit form only
->datetime('created_at')->hideFromEdit()
// Hide from detail view only
->string('internal_notes', 255)->hideFromView()
// Virtual field (not in database)
->string('full_name', 100)->excludeFromDatabase();
}
TableBuilder Column Control
1. Reset and Rebuild Columns
Use resetFields() to start with a clean slate and show only the columns you explicitly define.
How resetFields() Works
When you call resetFields(), all existing columns are hidden. Then, as you call field() or column(), those columns become visible in the exact order you define them.
$table = TableBuilder::create($model, 'posts_table')
->resetFields() // Hide ALL existing columns
// Only these columns will be shown, in this exact order:
->field('id')
->label('ID')
->field('title')
->label('Article Title')
->link('?page=posts&action=edit&id=%id%')
->field('status')
->label('Status')
->field('created_at')
->label('Published')
->getTable();
// Result: Table shows only id, title, status, created_at (in that order)
// All other model columns are hidden
2. Define Columns in Order
Simply calling field() or column() automatically positions new columns in sequence.
Automatic Column Ordering (New Feature)
When you add fields with field(), they are automatically positioned after the previous field you defined. No need to manually reorder unless you use moveBefore()!
$table = TableBuilder::create($model, 'users_table')
// Columns appear in the order you define them
->field('id') // 1st column
->field('username') // 2nd column (automatically after 'id')
->field('email') // 3rd column (automatically after 'username')
->field('status') // 4th column (automatically after 'email')
->field('created_at') // 5th column (automatically after 'status')
->getTable();
3. Hide Specific Columns
Use hide() in the field chain or hideColumns() for multiple columns.
$table = TableBuilder::create($model, 'posts_table')
// Hide single column
->field('id')
->hide() // Column exists in query but not displayed
// Hide multiple columns at once
->hideColumns(['internal_notes', 'draft_content', 'temp_data'])
->getTable();
4. Move Column Before Another
Use moveBefore() to reposition a single column.
Important Behavior with moveBefore()
When you use moveBefore(), the next field you define will be positioned after the field that was BEFORE the move, not after the moved field. This prevents the automatic ordering from following the moved column.
$table = TableBuilder::create($model, 'posts_table')
->field('id') // Position: 1st
->field('title') // Position: 2nd (after 'id')
->field('status') // Position: 3rd (after 'title')
->moveBefore('id') // Move 'status' before 'id'
// New order: status, id, title
->field('created_at') // Position: after 'title' (not after 'status'!)
// Final order: status, id, title, created_at
->getTable();
5. Complete Column Reordering
Use reorderColumns() to specify the exact order of all columns.
IMPORTANT: Call reorderColumns() at the END!
Always call reorderColumns() AFTER all your field() calls. If you call field() after reorderColumns(), the automatic ordering will position the new field and may override your manual ordering!
$table = TableBuilder::create($model, 'courses_table')
// First: Configure all your fields
->field('ATTIVO_CRS')
->label('Active')
->type('select')
->options(['0' => 'No', '1' => 'Yes'])
->field('CORSO')
->label('Course Name')
// Last: Define the exact column order
->reorderColumns(['ATTIVO_CRS', 'CORSO', 'DESCRIZIONE', 'DATA_INIZIO', 'DATA_FINE'])
->getTable();
// Columns will appear in the exact order specified in reorderColumns()