Columns & Fields Basics
The grid and the create/edit form are configured completely independently - ->columns() controls one, ->fields() controls the other.
->columns() controls the grid
->columns($columns, $reverse = false) restricts and orders which fields the LIST (grid) view shows. $columns is a comma-separated string or an array of field names, shown in exactly that order. Never called at all: the grid shows every column, in the table's natural order.
| Parameter | Type | Default | Description |
|---|---|---|---|
$columns | string|array | - | Comma-separated field list, or an array of field names, in display order |
$reverse | bool | false | When true, $columns means "every field EXCEPT these" instead of "only these" |
Setting $reverse = true is handy for a wide table where you only want to hide one or two noisy columns rather than re-list everything else:
$xcrud->columns('internalNotes', true); // show every column except internalNotes
->fields() controls the form
->fields($fieldList, $useTabs = false, $sectionName = '') restricts and orders which columns the CREATE/EDIT FORM shows - a completely separate concern from ->columns(). A field can appear in the grid but not the form, or the form but not the grid; each method only ever affects its own surface.
| Parameter | Type | Default | Description |
|---|---|---|---|
$fieldList | string | - | Comma-separated field list, in the order the form should show them |
$useTabs | bool | false | When multiple fields() calls each pass a $sectionName, turns those sections into a tab switcher instead of stacked labeled sections |
$sectionName | string | '' | Groups this call's $fieldList under a named section/tab label |
See Field Grouping, Tabs & Rich Text for the full tabs/sections write-up.
Sorting and labeling
->order_by($field, $direction = 'asc') sets the grid's initial sort - visitors can still click a column header to re-sort afterward.
| Parameter | Type | Default | Description |
|---|---|---|---|
$field | string | - | Column to sort by initially |
$direction | string | 'asc' | 'asc' or 'desc' |
->label($field, $label) sets a custom display name for a field, used in BOTH the grid's column header and the form's field label - one call covers both surfaces.
| Parameter | Type | Default | Description |
|---|---|---|---|
$field | string | - | The underlying column name |
$label | string | - | Display text shown instead of the raw column name |
Putting it together
$xcrud = Xcrud::get_instance();
$xcrud->table('customers');
$xcrud->route('customers');
// Grid: only these three columns, customerName first
$xcrud->columns('customerName,city,creditLimit');
$xcrud->order_by('customerName', 'asc');
// Form: a different, larger field set
$xcrud->fields('customerName,contactFirstName,contactLastName,city,creditLimit,phone');
$xcrud->label('creditLimit', 'Credit Limit ($)');
$xcrud->render();