-
-
Save brunoconstantino/3a6fe8b37b5fb93fee305cab6da6a31f to your computer and use it in GitHub Desktop.
Tela para selecionar colunas em listagem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Bruno Constantino 12-09-2022 | |
/* | |
Crie uma Nova Ação no Cabeçalho; | |
Defina o nome da variável como "btnShowColumns"; | |
Defina a Variável com escopo a nivel de classe como SIM; | |
Defina como método estático; | |
Defina o método como "onShowColumnsFilters"; | |
Copie os trechos de código abaixo em seus respectivos locais definidos no Adianti Builder; | |
*/ | |
//<onAfterColumnsCreation> | |
// COLUNAS: Define quais colunas devem exibir. | |
$customColumns = null; | |
if($customColumns = TSession::getValue(__CLASS__.'_columns_data')) | |
{ | |
foreach ($this->datagrid->getColumns() as $dg_column) | |
{ | |
$visible = false; | |
foreach ($customColumns as $column) | |
{ | |
if($column == $dg_column->getName()) | |
{ | |
$visible = true; | |
} | |
} | |
$dg_column->setVisibility($visible); | |
} | |
} | |
//</onAfterColumnsCreation> | |
//<onAfterHeaderActionsCreation> | |
// COLUNAS: Exibe label com quantidade | |
if($customColumns) | |
{ | |
$this->btnShowColumns->style = 'position: relative'; | |
$countColumns = count($customColumns ?? []); | |
$this->btnShowColumns->setLabel($this->btnShowColumns->getLabel(). "<span class='badge badge-success' style='position: absolute'>{$countColumns}<span>"); | |
} | |
//</onAfterHeaderActionsCreation> | |
public static function onShowColumnsFilters($param = null) | |
{ | |
try | |
{ | |
// COLUNAS: | |
$filter = new self([]); | |
if(isset($param['processar'])) | |
{ | |
$data = null; | |
if($param['processar'] == 1) | |
{ | |
$data = $_REQUEST['colunas'] ?? null; | |
} | |
TSession::setValue(__CLASS__ . '_columns_data', $data); | |
TScript::create('Template.closeRightPanel()'); | |
TApplication::loadPage(__CLASS__, 'onReload', []); | |
return; | |
} | |
$items = array(); | |
// Captura as colunas do datagrid | |
$datagrid_colunas = $filter->datagrid->getColumns(); | |
foreach($datagrid_colunas as $coluna) | |
{ | |
// name: colecao->nome | |
// label: Coleção | |
$items[$coluna->getName()] = $coluna->getLabel(); | |
} | |
// Cria uma cortina lateral com o campo Colunas. | |
$form = new BootstrapFormBuilder(self::$formName); | |
$form->setFormTitle("Selecione as Colunas"); | |
$colunas = new TCheckGroup('colunas'); | |
$colunas->addItems($items); | |
$colunas->setLayout('horizontal'); | |
$colunas->setBreakItems(5); | |
$colunas->setSize(200); | |
$row1 = $form->addFields([new TLabel("Colunas:", null, '14px', null, '100%'),$colunas]); | |
$row1->layout = ['col-sm-12']; | |
$columns_data = TSession::getValue(__CLASS__.'_columns_data'); | |
$data = new stdClass; | |
$data->colunas = $columns_data; | |
$form->setData( $data ); | |
$taction_onsearch = new TAction([__CLASS__, 'onShowColumnsFilters'], ['processar' => 1]); | |
$btn_onsearch = $form->addAction("Definir colunas", $taction_onsearch, 'fas:search #ffffff'); | |
//$this->btn_onsearch = $btn_onsearch; | |
$btn_onsearch->addStyleClass('btn-primary'); | |
$taction_limparcolunas = new TAction([__CLASS__, 'onShowColumnsFilters'], ['processar' => 2]); | |
$btn_limpar_colunas = $form->addAction("Limpar colunas", $taction_limparcolunas, 'fas:search #ffffff'); | |
$btn_limpar_colunas->addStyleClass('btn-default'); | |
$btn_limpar_colunas->setImage('fas:eraser #f44336'); | |
$btnClose = new TButton('closeCurtain'); | |
$btnClose->class = 'btn btn-sm btn-default'; | |
$btnClose->style = 'margin-right:10px;'; | |
$btnClose->onClick = "Template.closeRightPanel();"; | |
$btnClose->setLabel("Fechar"); | |
$btnClose->setImage('fas:times'); | |
$form->addHeaderWidget($btnClose); | |
$page = new TPage(); | |
$page->setTargetContainer('adianti_right_panel'); | |
$page->setProperty('page-name', __CLASS__ . 'Column'); | |
$page->setProperty('page_name', __CLASS__ . 'Column'); | |
$page->adianti_target_container = 'adianti_right_panel'; | |
$page->target_container = 'adianti_right_panel'; | |
$page->add($form); | |
$page->setIsWrapped(true); | |
$page->show(); | |
//</autoCode> | |
} | |
catch (Exception $e) | |
{ | |
new TMessage('error', $e->getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment