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. Usage
  2. Base Usage

Create a Grid

To create a grid, you need to extend the BaseLaraGrid class and implement the getColumns, and getDataSource methods.

use BoredProgrammers\LaraGrid\Components\ColumnComponents\Column;
use BoredProgrammers\LaraGrid\Livewire\BaseLaraGrid;
use Illuminate\Database\Eloquent\Builder;
use BoredProgrammers\LaraGrid\Filters\FilterResetButton;

class MyGrid extends BaseLaraGrid
{

    protected function getColumns(): array
    {
        return [
            Column::make('id', 'ID'),
            Column::make('name', 'Name'),
            // Add more columns as needed
        ];
    }

    protected function getDataSource(): Builder
    {
        return MyModel::query();
    }

}

In the getColumns method, you define the columns that will be displayed in the grid. The Column::make method takes two arguments: the model field and the label.

The getDataSource method should return an instance of Illuminate\Database\Eloquent\Builder for the model you want to display in the grid.

PreviousBase UsageNextDisplay a Grid

Last updated 1 year ago

Was this helpful?