Skip to content

Commit 66f4d67

Browse files
committed
Merge branch 'render-using-layouts' into 2.0
2 parents ec85a70 + 723e1d4 commit 66f4d67

File tree

11 files changed

+593
-320
lines changed

11 files changed

+593
-320
lines changed

src/Filters/AddsColumnFilters.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function addDateFilter(
8585
{
8686
$filter = new GenericFilter([
8787
'name' => $elementId,
88-
'id' => $elementId,
88+
'id' => $this->createElementId($elementId),
8989
'enabled' => $enabled,
9090
'formId' => $this->getFilterFormId(),
9191
'class' => 'form-control grid-datepicker grid-filter ' . $elementClass,
@@ -119,7 +119,7 @@ protected function addTextFilter($enabled, $elementId, $elementClass = null): Ge
119119
{
120120
$filter = new GenericFilter([
121121
'name' => $elementId,
122-
'id' => $elementId,
122+
'id' => $this->createElementId($elementId),
123123
'enabled' => $enabled,
124124
'formId' => $this->getFilterFormId(),
125125
'class' => 'form-control grid-filter ' . $elementClass,
@@ -143,7 +143,7 @@ protected function addSelectFilter($enabled, $elementId, $data, $elementClass =
143143
{
144144
$filter = new GenericFilter([
145145
'name' => $elementId,
146-
'id' => $elementId,
146+
'id' => $this->createElementId($elementId),
147147
'enabled' => $enabled,
148148
'formId' => $this->getFilterFormId(),
149149
'type' => 'select',
@@ -152,4 +152,15 @@ protected function addSelectFilter($enabled, $elementId, $data, $elementClass =
152152
]);
153153
return $filter;
154154
}
155+
156+
/**
157+
* Create the ID for the grid filter
158+
*
159+
* @param $elementId
160+
* @return string
161+
*/
162+
protected function createElementId($elementId): string
163+
{
164+
return 'grid-filter-' . $elementId;
165+
}
155166
}

src/Grid.php

Lines changed: 2 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ abstract class Grid implements Htmlable, GridInterface, GridButtonsInterface, Gr
3131
CreatesColumns,
3232
ConfiguresRoutes,
3333
AddsColumnFilters,
34-
RendersButtons;
34+
RendersButtons,
35+
RendersGrid;
3536

3637
/**
3738
* Specify if the rows on the table should be clicked to navigate to the record
@@ -40,13 +41,6 @@ abstract class Grid implements Htmlable, GridInterface, GridButtonsInterface, Gr
4041
*/
4142
protected $linkableRows = false;
4243

43-
/**
44-
* Specify if the footer section needs to be displayed
45-
*
46-
* @var bool
47-
*/
48-
protected $showFooter = false;
49-
5044
/**
5145
* The id of the grid. Many grids can exist on the same page, but the ID has to be unique
5246
*
@@ -117,13 +111,6 @@ abstract class Grid implements Htmlable, GridInterface, GridButtonsInterface, Gr
117111
*/
118112
protected $tableColumns = [];
119113

120-
/**
121-
* Controls rendering or not, for the search form
122-
*
123-
* @var bool
124-
*/
125-
protected $shouldRenderSearchForm = true;
126-
127114
/**
128115
* Create the grid
129116
*
@@ -149,17 +136,6 @@ public function create(array $params): GridInterface
149136
return $this;
150137
}
151138

152-
/**
153-
* Define rendering of the search form
154-
*
155-
* @return GridInterface
156-
*/
157-
public function withoutSearchForm(): GridInterface
158-
{
159-
$this->shouldRenderSearchForm = false;
160-
return $this;
161-
}
162-
163139
/**
164140
* Get the selected sort direction
165141
*
@@ -226,24 +202,6 @@ public function getName(): string
226202
return $this->name;
227203
}
228204

229-
/**
230-
* If the grid should show a footer
231-
*
232-
* @return bool
233-
*/
234-
public function shouldShowFooter(): bool
235-
{
236-
return $this->showFooter;
237-
}
238-
239-
/**
240-
* @param bool $showFooter
241-
*/
242-
public function setShowFooter(bool $showFooter): void
243-
{
244-
$this->showFooter = $showFooter;
245-
}
246-
247205
/**
248206
* Transform the name of the grid, to a short, identifier
249207
* Useful for route param names
@@ -320,37 +278,6 @@ protected function setGridDataItems(array $result): void
320278
}
321279
}
322280

323-
/**
324-
* Grid should render search form
325-
*
326-
* @return bool
327-
*/
328-
public function shouldRenderSearchForm()
329-
{
330-
return $this->shouldRenderSearchForm;
331-
}
332-
333-
/**
334-
* Render the search form on the grid
335-
*
336-
* @return string
337-
* @throws \Throwable
338-
*/
339-
public function renderSearchForm()
340-
{
341-
$params = func_get_args();
342-
$data = [
343-
'colSize' => $this->getGridToolbarSize()[0], // size
344-
'action' => $this->getSearchUrl(),
345-
'id' => $this->getSearchFormId(),
346-
'name' => $this->getGridSearchParam(),
347-
'dataAttributes' => [],
348-
'placeholder' => $this->getSearchPlaceholder(),
349-
];
350-
351-
return view($this->getGridSearchView(), array_merge($data, $params))->render();
352-
}
353-
354281
/**
355282
* Get the form id used for search
356283
*
@@ -445,45 +372,6 @@ public function toHtml()
445372
return $this->render();
446373
}
447374

448-
/**
449-
* Render the grid as HTML on the user defined view
450-
*
451-
* @return string
452-
* @throws \Throwable
453-
*/
454-
public function render()
455-
{
456-
return view($this->getGridView(), $this->compactData(func_get_args()))->render();
457-
}
458-
459-
/**
460-
* Specify the data to be sent to the view
461-
*
462-
* @param array $params
463-
* @return array
464-
* @throws \Exception
465-
*/
466-
protected function compactData($params = [])
467-
{
468-
$data = [
469-
'grid' => $this,
470-
'columns' => $this->processColumns()
471-
];
472-
return array_merge($data, $this->getExtraParams($params));
473-
}
474-
475-
/**
476-
* Any extra parameters that need to be passed to the grid
477-
* $params is func_get_args() passed from render
478-
*
479-
* @param array $params
480-
* @return array
481-
*/
482-
public function getExtraParams($params)
483-
{
484-
return array_merge($this->extraParams, $params);
485-
}
486-
487375
/**
488376
* Override this method and return a callback so that linkable rows are applied
489377
*
@@ -567,23 +455,4 @@ public function getHeaderClass(): string
567455
{
568456
return $this->getGridDefaultHeaderClass();
569457
}
570-
571-
/**
572-
* Pass the grid on to the user defined view e.g an index page, along with any data that may be required
573-
* Will dynamically switch between displaying the grid and downloading exported files
574-
*
575-
* @param string $viewName the view name
576-
* @param array $data any extra data to be sent to the view
577-
* @param string $as the variable to be sent to the view, representing the grid
578-
*
579-
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
580-
* @throws \Throwable
581-
*/
582-
public function renderOn(string $viewName, $data = [], $as = 'grid')
583-
{
584-
if ($this->getRequest()->has($this->getGridExportParam())) {
585-
return $this->exportHandler->export();
586-
}
587-
return view($viewName, array_merge($data, [$as => $this]));
588-
}
589458
}

src/GridInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ interface GridInterface
1616
* Create the grid
1717
*
1818
* @param array $params
19-
* @return GridInterface
19+
* @return $this
2020
*/
21-
public function create(array $params): GridInterface;
21+
public function create(array $params): self;
2222

2323
/**
2424
* Initialize grid variables

src/HasGridConfigurations.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ trait HasGridConfigurations
156156
*/
157157
private $gridFooterClass;
158158

159+
/**
160+
* @var string
161+
*/
162+
private $gridTemplateView;
163+
164+
public function getGridTemplateView(): string
165+
{
166+
if ($this->gridTemplateView === null) {
167+
$this->gridTemplateView = config('grid.templates.view', 'leantony::grid.templates.bs4-card');
168+
}
169+
return $this->gridTemplateView;
170+
}
171+
159172
public function getGridFooterClass(): string
160173
{
161174
if ($this->gridFooterClass === null) {

0 commit comments

Comments
 (0)