Add display options to static datatables

This commit is contained in:
Stephen Abello
2021-03-08 16:09:38 +01:00
parent ef871fba7f
commit b300b76783
3 changed files with 43 additions and 4 deletions

View File

@@ -799,7 +799,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
return $aOptions;
}
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null, array $aExtraParams = [], string $sFilter = "")
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null, array $aExtraParams = [], string $sFilter = "", array $aOptions = [])
{
$oBlock = new UIContentBlock();
$oTitle = TitleUIBlockFactory::MakeNeutral($sTitle, 3);
@@ -808,6 +808,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$oTable->SetColumns($aColumns);
$oTable->SetData($aData);
$oTable->SetFilter($sFilter);
$oTable->SetOptions($aOptions);
$oBlock->AddSubBlock($oTable);

View File

@@ -58,6 +58,10 @@ class StaticTable extends UIContentBlock
private $aExtraParams;
/*@var string $sUrlForRefresh*/
private $sFilter;
/** @var array $aOptions
* List of specific options for display datatable
*/
private $aOptions;
public function __construct(string $sId = null, array $aContainerCSSClasses = [], array $aExtraParams = [])
{
@@ -65,6 +69,7 @@ class StaticTable extends UIContentBlock
$this->aColumns = [];
$this->aData = [];
$this->aExtraParams = $aExtraParams;
$this->aOptions = [];
}
/**
@@ -122,4 +127,34 @@ class StaticTable extends UIContentBlock
$('#".$this->sId."').dataTable().fnAddData(data);
});";
}
/**
* @return mixed
*/
public function GetOption(string $sOption)
{
if (isset($this->aOptions[$sOption])) {
return $this->aOptions[$sOption];
}
return null;
}
/**
* @return array
*/
public function GetOptions(): array
{
return $this->aOptions;
}
/**
* @param array $aOptions
*
* @return $this
*/
public function SetOptions($aOptions)
{
$this->aOptions = $aOptions;
return $this;
}
}

View File

@@ -1,10 +1,10 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% if oUIBlock.GetOptions() is not empty %}
{% set iPageSize = oUIBlock.GetOptions()["iPageSize"] %}
{% if oUIBlock.GetOption("iPageSize") is not empty %}
{% set iPageSize = oUIBlock.GetOption("iPageSize") %}
{% else %}
{% set iPageSize = 10 %}
{% set iPageSize = 10 %}
{% endif %}
$('#{{ oUIBlock.GetId() }}').DataTable({
@@ -34,6 +34,9 @@ $('#{{ oUIBlock.GetId() }}').DataTable({
autoWidth: false,
rowId: "id",
filter: false,
{% if oUIBlock.GetOption("pageLength") is not empty %}
pageLength: {{ oUIBlock.GetOptions()["pageLength"] }},
{% endif %}
{% if oUIBlock.GetData()|length <= iPageSize %}
paging: false,
{% endif %}