Include Columns

Table columns are controlled by the columns() method.

You can find this method is inside your PowerGrid file (e.g., DishTable.php).

WARNING

Before proceeding, check if you have Added the column in order to have it available for including.

Usage

To display a column to your table, include a new Column::add() in the columns() method.

Place your code inside the method's return [] statement.

You should always provide both title() and field(). View all Column Methods.

Example:

public function columns(): array
{
     return [
         Column::add()
             ->title('ID')
             ->field('id'),
        
         Column::add()
             ->title('Dish name')
             ->field('name')
             ->searchable(),
        
         Column::add()
             ->title('Price + taxes')
             ->field('price_after_taxes')
              ->sortable(),
      ];
}

or using make() method

public function columns(): array
{
     return [
         Column::make(title: 'ID', field: 'id'),

         Column::make(title: 'Dish name', field: 'name')
            ->searchable(),

         Column::make(title: 'Price + taxes', field: 'price_after_taxes')
             ->sortable(),
  ];
}

Column Methods

The methods below can be chained to the PowerComponents\LivewirePowerGrid\Column class.

add

Adds a new column to your PowerGrid Table.

Example:

Column::add()
 

title

  • Sets a title in the column header.
Parameter
(string) $string

Example:

Column::add()
    ->title('Price in EUR'),

 

TIP

You can translate your title using Laravel's translation stringsopen in new window feature.


placeholder

Parameter
(string) $placeholder

Example:

Column::add()
    ->placeholder('Placeholder Description'),

 

field

ParameterDescription
(string) $fielddatabase table field name or array field
(string) $dataFieldOptionally, you may pass a second parameter $dataField referring to the data source table and field. This is useful when you join tables and must maintain unique field names.

Example:

Column::add()
    ->field('price_formatted'),

 

With dataField:

Column::add()
    ->field('category_name', 'categories.name'),

 

searchable

By default, columns are not included when searching with Search Input.

This method allows the column's content to be searched with this feature.

Example:

Column::add()
    ->searchable(),

 

sortable

  • Adds a sort button to the column header.

Example:

Column::add()
    ->sortable(),

 

WARNING

If your column fetches data via relationship, you must join the related table in your Datasource query.


hidden

  • Hides the column in your PowerGrid table.

Example:

Column::add()
    ->hidden(),

 

visibleInExport

  • This method can be useful when you want a column to appear in the file but not at the web-page.
ParameterDescription
(bool) $visibleWhen true, the column when be included when using the export to file function.

Example:

Column::add()
    ->title('Postal envelope data')
    ->field('postal_data')
    ->hidden()
    ->visibleInExport(true),




 

headerAttribute

ParameterDescription
(string) $classHTML class
(string) $styleHTML style

Adds the class or style to the column header.

Example:

Column::add()
    ->headerAttribute('text-center', 'color:red')

 

bodyAttribute

  • Adds the class or style to each table row in this column.
ParameterDescription
(string) $classHTML class
(string) $styleHTML style

Example:

Column::add()
    ->bodyAttribute('text-center', 'color:red')

 

contentClassField

  • Adds the contents of the specified database column to the Table Column content <span> CSS class attribute.
ParameterDescription
(string) $dataFieldDatabase Column

Example:

Column::add()
    ->contentClassField('status_class')

 

contentClasses

  • Adds the corresponding value of the key matching the column content in the provided array to the Table Column content <span> CSS class attribute.
ParameterDescription
(array) $arrayColumn content => CSS Class assignments

Example:

Column::add()
    ->contentClasses([
          'In Progress' => 'text-blue-600',
          'Completed' => 'text-green-600'
     ])