LaraGrid
  • LaraGrid
  • Installation
  • Publishable
  • Usage
    • Base Usage
      • Create a Grid
      • Display a Grid
    • Examples
  • Theme
    • Default Theme
    • Customize the Theme
  • Column
    • Description
    • Create a Column
    • Methods
    • Usage
  • Column Group
    • Description
    • Create a ColumnGroup
    • Methods
    • Usage
  • Filter
    • Description
    • Available Filters
    • Usage
    • Custom Builder
    • Custom filter
    • Show filtering and sorting in url
  • Filter Reset Button
    • Description
    • Usage
    • Customization
  • Layout
    • Description
    • Usage
  • PowerJoins in LaraGrid
    • Why do we use it
Powered by GitBook
On this page

Was this helpful?

  1. Column

Methods

The Column class provides several methods to manipulate a column in the grid.

setFilter(BaseFilter $filter)

This method sets a filter for the column. Available filters are: TextFilter, DateFilter, SelectFilter, BooleanFilter.

public function setFilter(BaseFilter $filter): static

setRecordField(?string $recordField)

This method sets the model field of the column.

public function setRecordField(?string $recordField): void

setSortable($isSortable = true)

This method enables or disables sorting for a column.

public function setSortable($isSortable = true): static

setDateFormat(string $dateFormat)

This method sets the date format used to display date values in the column.

public function setDateFormat(string $dateFormat): static

setTag(string $tag): static

This method sets the tag of the column. The default tag is td.

public function setTag(string $tag): static

setRenderer(callable $renderer): static

This method sets the renderer for the column. You can pass a callable, a class method, or a string.

public function setRenderer(callable $renderer): static
Column::make(label: 'Name')
    ->setRenderer(function ($record) {
        return $record->name;
    })
    ->setRenderer([MyClass::class, 'myMethod'])
    ->setRenderer('Random Text')
class MyClass
{
    public static function myMethod($record)
    {
        return $record->name;
    }
}

setAttributes(array $attributes): static

This method sets the attributes of the column. The attributes are HTML attributes that are applied to the column tag. You can pass a callable, a class method or an array.

public function setAttributes(callable|array $attributes): static
Column::make(label: 'Name')
    ->setAttributes(function ($record) {
        return [
            'class' => 'text-center',
            'data-id' => $record->id,
            'wire:click.prevent' => 'download(' . $record->id . ')',
        ];
    })
    ->setAttributes([MyClass::class, 'myMethod'])
    ->setAttributes(['class' => 'bg-red-500'])
class MyClass
{
    public static function myMethod($record)
    {
        return [
            'class' => 'text-center',
            'data-id' => $record->id,
            'wire:click.prevent' => 'download(' . $record->id . ')',
        ];
    }
}
PreviousCreate a ColumnNextUsage

Last updated 1 year ago

Was this helpful?