-
Notifications
You must be signed in to change notification settings - Fork 922
add Datagrid and Datalist components #5810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
3635809
994a8ae
64b8fae
59aec28
a4c26a2
e203a33
efbe5e9
979484a
1e8e186
e4f8f46
0028f88
23f89a4
50b42e4
bbd4421
bb53b44
acca4ac
d7ffc4a
35dbd19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
tabacitu marked this conversation as resolved.
Show resolved
Hide resolved
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use EditableColumns inside this component?! What happens then?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't work - they throw a JS error. Buuuut. I don't think it's because of the component itself... because they don't work inside the ShowOperation either! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace Backpack\CRUD\app\View\Components; | ||
|
|
||
| use Illuminate\View\Component; | ||
|
|
||
| class Datagrid extends Component | ||
| { | ||
| public $entry; | ||
| public $crud; | ||
| public $columns; | ||
| public $displayButtons; | ||
|
|
||
| /** | ||
| * Create a new component instance. | ||
| */ | ||
| public function __construct($entry, $crud = null, $columns = [], $displayButtons = true) | ||
tabacitu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| $this->columns = $columns ?? $crud?->columns() ?? []; | ||
| $this->entry = $entry; | ||
| $this->crud = $crud; | ||
| $this->displayButtons = $displayButtons; | ||
| } | ||
|
|
||
| /** | ||
| * Get the view / contents that represent the component. | ||
| */ | ||
| public function render() | ||
| { | ||
| // if no columns are set, don't load any view | ||
| if (empty($this->columns)) { | ||
| return ''; | ||
| } | ||
|
|
||
| return view('crud::components.datagrid'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace Backpack\CRUD\app\View\Components; | ||
|
|
||
| use Illuminate\View\Component; | ||
|
|
||
| class Datalist extends Component | ||
| { | ||
| public $entry; | ||
| public $crud; | ||
| public $columns; | ||
| public $displayButtons; | ||
|
|
||
| /** | ||
| * Create a new component instance. | ||
| */ | ||
| public function __construct($entry, $crud = null, $columns = [], $displayButtons = true) | ||
tabacitu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| $this->columns = $columns ?? $crud?->columns() ?? []; | ||
| $this->entry = $entry; | ||
| $this->crud = $crud; | ||
| $this->displayButtons = $displayButtons; | ||
| } | ||
|
|
||
| /** | ||
| * Get the view / contents that represent the component. | ||
| */ | ||
| public function render() | ||
| { | ||
| // if no columns are set, don't load any view | ||
| if (empty($this->columns)) { | ||
| return ''; | ||
| } | ||
|
|
||
| return view('crud::components.datalist'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1180,3 +1180,108 @@ div.dt-scroll-body { | |
| margin-left: 2px; | ||
| margin-right: auto; | ||
| } | ||
|
|
||
| /* DataGrid Component */ | ||
|
|
||
| /* Base mobile-first layout: 1 column */ | ||
| .bp-datagrid { | ||
| display: grid; | ||
| grid-gap: 1.5rem; | ||
| grid-template-columns: 1fr; | ||
| } | ||
|
|
||
| .bp-datagrid-title { | ||
| font-size: .625rem; | ||
| font-weight: 600; | ||
| text-transform: uppercase; | ||
| letter-spacing: .04em; | ||
| line-height: 1rem; | ||
| color: #66626c; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tabacitu put this color in a CSS variable |
||
| margin-bottom: 0.25rem; | ||
| } | ||
|
|
||
| /* Breakpoint 1: Small screens (≥768px) — 6 columns */ | ||
| @media (min-width: 768px) { | ||
| .bp-datagrid { | ||
| grid-template-columns: repeat(6, 1fr); | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-1 { | ||
| grid-column: span 1 / span 1; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-2 { | ||
| grid-column: span 2 / span 2; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-3 { | ||
| grid-column: span 3 / span 3; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-4 { | ||
| grid-column: span 4 / span 4; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-5 { | ||
| grid-column: span 5 / span 5; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-6 { | ||
| grid-column: span 6 / span 6; | ||
| } | ||
| } | ||
|
|
||
| /* Breakpoint 2: Large screens (≥1024px) — 12 columns */ | ||
| @media (min-width: 1024px) { | ||
| .bp-datagrid { | ||
| grid-template-columns: repeat(12, 1fr); | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-1 { | ||
| grid-column: span 1 / span 1; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-2 { | ||
| grid-column: span 2 / span 2; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-3 { | ||
| grid-column: span 3 / span 3; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-4 { | ||
| grid-column: span 4 / span 4; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-5 { | ||
| grid-column: span 5 / span 5; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-6 { | ||
| grid-column: span 6 / span 6; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-7 { | ||
| grid-column: span 7 / span 7; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-8 { | ||
| grid-column: span 8 / span 8; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-9 { | ||
| grid-column: span 9 / span 9; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-10 { | ||
| grid-column: span 10 / span 10; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-11 { | ||
| grid-column: span 11 / span 11; | ||
| } | ||
|
|
||
| .bp-datagrid-item.size-12 { | ||
| grid-column: span 12 / span 12; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <div class="bp-datagrid p-3"> | ||
| @foreach($columns as $column) | ||
| <div class="bp-datagrid-item size-{{ $column['size'] ?? '3' }}"> | ||
| <div class="bp-datagrid-title">{!! $column['label'] !!}</div> | ||
| <div class="bp-datagrid-content"> | ||
| @includeFirst(\Backpack\CRUD\ViewNamespaces::getViewPathsWithFallbackFor('columns', $column['type'], 'crud::columns.text')) | ||
| </div> | ||
| </div> | ||
| @endforeach | ||
|
|
||
| @if($displayButtons ?? $crud && $crud->buttons()->where('stack', 'line')->count()) | ||
| <div class="bp-datagrid-item size-12"> | ||
| <div class="bp-datagrid-title">{{ trans('backpack::crud.actions') }}</div> | ||
| <div class="bp-datagrid-content"> | ||
| @include('crud::inc.button_stack', ['stack' => 'line']) | ||
| </div> | ||
| </div> | ||
| @endif | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <table class="table table-striped m-0 p-0"> | ||
| <tbody> | ||
| @foreach($columns as $column) | ||
| <tr> | ||
| <td @if($loop->index === 0) class="border-top-0" @endif> | ||
| <strong>{!! $column['label'] !!}@if(!empty($column['label'])):@endif</strong> | ||
| </td> | ||
| <td @if($loop->index === 0) class="border-top-0" @endif> | ||
| @includeFirst(\Backpack\CRUD\ViewNamespaces::getViewPathsWithFallbackFor('columns', $column['type'], 'crud::columns.text')) | ||
| </td> | ||
| </tr> | ||
| @endforeach | ||
|
|
||
| @if($displayButtons && $crud && $crud->buttons()->where('stack', 'line')->count()) | ||
| <tr> | ||
| <td> | ||
| <strong>{{ trans('backpack::crud.actions') }}</strong> | ||
| </td> | ||
| <td> | ||
| @include('crud::inc.button_stack', ['stack' => 'line']) | ||
| </td> | ||
| </tr> | ||
| @endif | ||
| </tbody> | ||
| </table> |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unhappy with this file because it's now called We can probably
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep it like this for now, to keep changes to a minimum. We can rename/refactor in separate PRs if we think it's worth it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,7 @@ | ||
| @if(count($columns)) | ||
| <table class="table table-striped m-0 p-0"> | ||
| <tbody> | ||
| @foreach($columns as $column) | ||
| <tr> | ||
| <td @if($loop->index === 0) class="border-top-0" @endif> | ||
| <strong>{!! $column['label'] !!}@if(!empty($column['label'])):@endif</strong> | ||
| </td> | ||
| <td @if($loop->index === 0) class="border-top-0" @endif> | ||
| @php | ||
| // create a list of paths to column blade views | ||
| // including the configured view_namespaces | ||
| $columnPaths = array_map(function($item) use ($column) { | ||
| return $item.'.'.$column['type']; | ||
| }, \Backpack\CRUD\ViewNamespaces::getFor('columns')); | ||
|
|
||
| // but always fall back to the stock 'text' column | ||
| // if a view doesn't exist | ||
| if (!in_array('crud::columns.text', $columnPaths)) { | ||
| $columnPaths[] = 'crud::columns.text'; | ||
| } | ||
| @endphp | ||
| @includeFirst($columnPaths) | ||
| </td> | ||
| </tr> | ||
| @endforeach | ||
| @if($crud->buttons()->where('stack', 'line')->count() && ($displayActionsColumn ?? true)) | ||
| <tr> | ||
| <td> | ||
| <strong>{{ trans('backpack::crud.actions') }}</strong> | ||
| </td> | ||
| <td> | ||
| @include('crud::inc.button_stack', ['stack' => 'line']) | ||
| </td> | ||
| </tr> | ||
| @endif | ||
| </tbody> | ||
| </table> | ||
| @endif | ||
| <x-dynamic-component | ||
| :component="$crud->getOperationSetting('component')" | ||
| :entry="$entry" | ||
| :crud="$crud" | ||
| :columns="$columns" | ||
| :display-buttons="$displayActionsColumn ?? true" | ||
| /> |
Uh oh!
There was an error while loading. Please reload this page.