Skip to content

Commit b05f3d9

Browse files
committed
24.03.10
- Se genera el caption de la tabla. - Se corrige el problema con los iconos de las columnas que no se ordenan. - Versión de lanzamiento.
1 parent bc44308 commit b05f3d9

File tree

6 files changed

+75
-36
lines changed

6 files changed

+75
-36
lines changed

README.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
Laravel GridView
22
============
33

4-
Laravel GridView es un paquete para generar una tabla con datos. Permite generar de manera rápida una tabla a partir de un array de modelos Eloquent o Collections o también de arrays anidados, usando los atributos como columnas y cada fila es un modelo con sus datos.
4+
Laravel GridView es un paquete para generar una tabla con datos. Permite generar de manera rápida una tabla a partir de un array de modelos Eloquent o Collections, usando los atributos como columnas y cada fila es un modelo con sus datos.
55

6-
Instalación
7-
------------
6+
## Instalación
87

98
La forma preferida de instalar esta extensión es a través de [composer](http://getcomposer.org/download/).
109

@@ -29,28 +28,22 @@ Luego ejecute el siguiente comando _artisan_ para copiar los assets en el direct
2928
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-assets
3029
```
3130

32-
Sobrescribir la plantilla `Blade`
33-
---
31+
## Uso
3432

35-
Si desea sobrescribir la vista que genera la tabla, ejecute el siguiente comando para que copie los archivos de vista en
36-
_resources/views/vendor/gridview_:
37-
38-
```bash
39-
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-view
40-
```
33+
Una vez que la extensión está instalada, puede crear la tabla de la siguiente forma:
4134

42-
Si está usando GridView como componente, la vista será copiada en _resources/views/components_:
35+
Registre el servico en el archivo de configuración _app.php_ en la sección `providers`:
4336

44-
```bash
45-
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-component-view
37+
```php
38+
...
39+
/*
40+
* Package Service Providers...
41+
*/
42+
neoacevedo\gridview\Providers\GridViewServiceProvider::class,
43+
...
4644
```
4745

48-
Uso
49-
-----
50-
51-
Una vez que la extensión está instalada, puede crear la tabla de la siguiente forma:
52-
53-
Para Laravel 6+:
46+
Para Laravel 6.x o uso como clase:
5447

5548
```php
5649
{{ gridview()->widget([
@@ -113,7 +106,7 @@ Para Laravel 6+:
113106
]) }}
114107
```
115108

116-
Para Laravel 7+, se puede de la forma anterior, o como componente:
109+
Para Laravel >=7.x, se puede de la forma anterior, o como componente:
117110

118111
```php
119112
<x-package-gridview id="table" class="dataTable"
@@ -167,7 +160,7 @@ Para Laravel 7+, se puede de la forma anterior, o como componente:
167160
]" />
168161
```
169162

170-
Para la propiedad `dataProvider` puede pasarse un array o una colección. Para esta última desde el controlador puede pasarla desde la base de datos.
163+
La propiedad `dataProvider` tiene que ser de tipo `\Illuminate\Contracts\Pagination\LengthAwarePaginator` con el fin de generar el paginador.
171164

172165
En el array de columnas, puede especificar la clase que se encargará de renderizar el contenido de toda la columna a través de la propiedad `class`. Las clases de columna que soporta GridView son:
173166

@@ -177,11 +170,10 @@ En el array de columnas, puede especificar la clase que se encargará de renderi
177170
- `\neoacevedo\gridview\Column\RadioButtonColumn`: Columna que se encarga de renderizar inputs de radio
178171
- `\neoacevedo\gridview\Column\SerialColumn`: Columna que renderiza el número de cada fila.
179172

180-
Con cualquiera de las dos opciones, se obtendrá una tabla como la siguiente:
173+
Con cualquiera de las dos opciones, se obtendrá una tabla parecida a la siguiente:
181174

182175
```html
183-
<table data-toggle="table" data-pagination="true" id="bootstrap-table" class="table table-bordered table-hover">
184-
176+
<table id="bootstrap-table" class="table table-bordered table-hover">
185177
<thead>
186178
<tr>
187179
<th data-field="0">
@@ -268,3 +260,18 @@ Con cualquiera de las dos opciones, se obtendrá una tabla como la siguiente:
268260
</tbody>
269261
</table>
270262
```
263+
264+
### Sobrescribir la plantilla `Blade`
265+
266+
Si desea sobrescribir la vista que genera la tabla, ejecute el siguiente comando para que copie los archivos de vista en
267+
_resources/views/vendor/gridview_:
268+
269+
```bash
270+
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-view
271+
```
272+
273+
Si está usando GridView como componente, la vista será copiada en _resources/views/components_:
274+
275+
```bash
276+
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-component-view
277+
```

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"table"
1010
],
1111
"license": "GPL-3.0+",
12-
"minimum-stability": "dev",
12+
"minimum-stability": "stable",
1313
"prefer-stable": true,
14-
"version": "24.03.07-RC2",
14+
"version": "24.03.10",
1515
"authors": [
1616
{
1717
"name": "Néstor Acevedo",
@@ -37,4 +37,4 @@
3737
]
3838
}
3939
}
40-
}
40+
}

example.tar.gz

22.6 MB
Binary file not shown.

src/Column/DataColumn.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ protected function renderHeaderCellContent()
164164

165165
if ($this->attribute !== null && $this->enableSorting) {
166166
$sorted = request()->get('sort');
167-
$sortClass = substr($sorted, 0, 1) === '-' ? 'icon-link desc' : 'icon-link asc';
168-
$transform = substr($sorted, 0, 1) === '-' ? 'transform: rotate(-180deg);' : '';
167+
168+
if (substr($sorted, 1) === $this->attribute) {
169+
$sortClass = substr($sorted, 0, 1) === '-' ? 'icon-link desc' : 'icon-link asc';
170+
$transform = substr($sorted, 0, 1) === '-' ? 'transform: rotate(-180deg);' : '';
171+
} else {
172+
$sortClass = 'icon-link asc';
173+
$transform = '';
174+
}
169175

170176
$url = request()->fullUrlWithQuery(['sort' => substr($sorted, 0, 1) === '-' ? $this->attribute : '-' . $this->attribute]);
171177

src/GridView.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ public function getModels()
326326
return $this->dataProvider->items();
327327
}
328328

329+
/**
330+
* Renders the caption element.
331+
* @return bool|HtmlString
332+
*/
333+
public function renderCaption()
334+
{
335+
if (!empty($this->caption)) {
336+
$options = Html::renderTagAttributes($this->captionOptions);
337+
return str("<captions $options>{$this->caption}</caption")->toHtmlString();
338+
}
339+
return false;
340+
}
341+
329342
/**
330343
* Renders the HTML content indicating that the list view has no data.
331344
* @return string|HtmlString
@@ -373,7 +386,7 @@ public function renderFilters()
373386
*/
374387
public function renderItems(): string
375388
{
376-
// $caption = $this->renderCaption();
389+
$caption = $this->renderCaption();
377390
$columnGroup = $this->renderColumnGroup();
378391
$tableHeader = $this->showHeader ? $this->renderTableHeader() : false;
379392
$tableBody = $this->renderTableBody();
@@ -382,7 +395,7 @@ public function renderItems(): string
382395
$tableFooter = $this->renderTableFooter();
383396
}
384397
$content = array_filter([
385-
// $caption,
398+
$caption,
386399
$columnGroup,
387400
$tableHeader,
388401
$tableBody,
@@ -399,7 +412,7 @@ public function renderItems(): string
399412
*/
400413
public function renderPager(): string
401414
{
402-
$pagination = $this->dataProvider->hasPages();
415+
$pagination = $this->dataProvider->hasPages() ?? false;
403416

404417
if ($pagination === false) {
405418
return '';

src/View/Components/GridViewComponent.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function __construct(
301301
) {
302302
$this->dataProvider = $dataProvider;
303303

304-
$this->caption = $caption;
304+
$this->caption = (string) $caption;
305305

306306
$this->captionOptions = $captionOptions;
307307

@@ -397,6 +397,19 @@ public function render()
397397
]);
398398
}
399399

400+
/**
401+
* Renders the caption element.
402+
* @return bool|HtmlString
403+
*/
404+
public function renderCaption()
405+
{
406+
if (!empty($this->caption)) {
407+
$options = Html::renderTagAttributes($this->captionOptions);
408+
return str("<caption $options>{$this->caption}</caption>")->toHtmlString();
409+
}
410+
return false;
411+
}
412+
400413
/**
401414
* Renders the column group HTML.
402415
* @return HtmlString|false
@@ -468,7 +481,7 @@ public function renderFilters()
468481
*/
469482
public function renderItems(): string
470483
{
471-
// $caption = $this->renderCaption();
484+
$caption = $this->renderCaption();
472485
$columnGroup = $this->renderColumnGroup();
473486
$tableHeader = $this->showHeader ? $this->renderTableHeader() : false;
474487
$tableBody = $this->renderTableBody();
@@ -477,7 +490,7 @@ public function renderItems(): string
477490
$tableFooter = $this->renderTableFooter();
478491
}
479492
$content = array_filter([
480-
// $caption,
493+
$caption,
481494
$columnGroup,
482495
$tableHeader,
483496
$tableBody,

0 commit comments

Comments
 (0)