Skip to content

Commit

Permalink
Fix table filtering pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimonka2 committed Jul 6, 2020
1 parent 869c2b1 commit 81d3471
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Form/Components/Table/Formatter/ElementMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ElementMapping
'date' => Date::class,
'number' => Number::class,
'state' => State::class,
'link' => Link::class,
];

static protected function getBinding($type)
Expand Down
39 changes: 39 additions & 0 deletions src/Form/Components/Table/Formatter/Link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace dimonka2\flatform\Form\Components\Table\Formatter;

use Illuminate\Support\Str;
use dimonka2\flatform\Flatform;
use dimonka2\flatform\Traits\SettingReaderTrait;
use dimonka2\flatform\Form\Components\Table\IColumnFormat;

class Link extends BaseFormatter implements IColumnFormat
{
use SettingReaderTrait;
protected $route;
protected $idField;
protected $emptyString;
protected $limit;


protected function read(array $definition)
{
$this->readSettings($definition, [
'route', 'idField', 'limit', 'emptyString',
]);
parent::read($definition);

}

protected function transformValue($value)
{
if(!$value) $value = $this->emptyString;
$limited = $value;
if($this->limit) $limited = Str::limit($limited, $this->limit, '...');
$link = ['a', 'href' => route($this->route, $this->row[$this->idField]), 'text' => $limited];
if($limited != $value) $link['tooltip'] = $value;
$value = Flatform::render([$link]);
return $value;
}


}
5 changes: 5 additions & 0 deletions src/Form/Components/Table/RowsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function getRow($index): ?Fluent
return $this->rows->getRow($index);
}

public function getRowCount()
{
return $this->rows->count();
}

/**
* Get the value of Rows
*/
Expand Down
20 changes: 20 additions & 0 deletions src/Form/Components/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,24 @@ public function getActions()
{
return $this->actions;
}

/**
* Get the value of page
*/
public function getPage()
{
return $this->page;
}

/**
* Set the value of page
*
* @return self
*/
public function setPage($page)
{
$this->page = $page;

return $this;
}
}
6 changes: 6 additions & 0 deletions src/Livewire/TableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ protected function ensureTable($prepareRows = false)
$this->addSelectCheckbox($table);
}
$table->buildRows();
if($this->page > 1 && $table->getRowCount() == 0) {
// try to rebuid
$this->page = 1;
$table->setPage(1);
$table->buildRows();
}
$this->rowsReady = true;
}

Expand Down

0 comments on commit 81d3471

Please sign in to comment.