Commit b55d3422 authored by Tino Goratsch's avatar Tino Goratsch

fix the *SortColumnRenderer

parent a6c03fff
......@@ -23,6 +23,10 @@ abstract class AbstractColumnRenderer implements ColumnRendererInterface
* @var bool
*/
private $useAjax = false;
/**
* @var int|null
*/
private $totalResults;
/**
* {@inheritdoc}
......@@ -78,6 +82,24 @@ abstract class AbstractColumnRenderer implements ColumnRendererInterface
return $this;
}
/**
* {@inheritdoc}
*/
public function getTotalResults(): ?int
{
return $this->totalResults;
}
/**
* {@inheritdoc}
*/
public function setTotalResults(int $totalResults)
{
$this->totalResults = $totalResults;
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -45,6 +45,18 @@ interface ColumnRendererInterface
*/
public function setUseAjax(bool $useAjax);
/**
* @return int|null
*/
public function getTotalResults(): ?int;
/**
* @param int $totalResults
*
* @return $this
*/
public function setTotalResults(int $totalResults);
/**
* @param array $column
* @param array $dbResultRow
......
......@@ -33,7 +33,12 @@ class NestedSetSortColumnRenderer extends SortColumnRenderer
}
$column['attribute'] += [
'sort' => $dbResultRow[$this->getFirstDbField($column)],
'sort' => \str_pad(
$dbResultRow[$this->getFirstDbField($column)],
\strlen($this->getTotalResults()),
'0',
STR_PAD_LEFT
),
];
return $this->render($column, $value);
......
......@@ -62,7 +62,7 @@ class SortColumnRenderer extends AbstractColumnRenderer
$column['attribute'] += [
'sort' => \str_pad(
$dbResultRow[$this->getFirstDbField($column)],
\strlen($dbResultRow['last']),
\strlen($this->getTotalResults()),
'0',
STR_PAD_LEFT
),
......
......@@ -8,6 +8,7 @@
namespace ACP3\Core\DataGrid;
use ACP3\Core\ACL;
use ACP3\Core\DataGrid\ColumnRenderer\ColumnRendererInterface;
use ACP3\Core\DataGrid\ColumnRenderer\HeaderColumnRenderer;
use ACP3\Core\DataGrid\ColumnRenderer\MassActionColumnRenderer;
use ACP3\Core\DataGrid\ColumnRenderer\OptionColumnRenderer;
......@@ -113,14 +114,19 @@ class DataGrid
private function mapTableColumnsToDbFieldsAjax(Input $input): array
{
$renderedResults = [];
$totalResults = $input->getResultsCount();
foreach ($input->getResults() as $result) {
$row = [];
foreach (clone $input->getColumns() as $column) {
if ($this->container->has($column['type']) && !empty($column['label'])) {
$row[] = $this->container->get($column['type'])
/** @var ColumnRendererInterface $columnRenderer */
$columnRenderer = $this->container->get($column['type']);
$row[] = $columnRenderer
->setIdentifier($input->getIdentifier())
->setPrimaryKey($input->getPrimaryKey())
->setUseAjax($this->isRequiredAjaxRequest($input))
->setTotalResults($totalResults)
->fetchDataAndRenderColumn($column, $result);
}
}
......@@ -163,14 +169,19 @@ class DataGrid
}
$renderedResults = '';
$totalResults = $input->getResultsCount();
foreach ($input->getResults() as $result) {
$renderedResults .= '<tr>';
foreach (clone $input->getColumns() as $column) {
if ($this->container->has($column['type']) && !empty($column['label'])) {
$renderedResults .= $this->container->get($column['type'])
/** @var ColumnRendererInterface $columnRenderer */
$columnRenderer = $this->container->get($column['type']);
$renderedResults .= $columnRenderer
->setIdentifier($input->getIdentifier())
->setPrimaryKey($input->getPrimaryKey())
->setUseAjax($this->isRequiredAjaxRequest($input))
->setTotalResults($totalResults)
->fetchDataAndRenderColumn($column, $result);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment