I have a little problem in yii2 framework.
I have DetailView widget
<?= DetailView::widget([
'model' => $table_1,
'attributes' => [
'year',
'table_zs_field_1',
'table_zs_field_2',
'table_zs_field_3',
'table_zs_field_4',
'table_zs_field_5',
'table_zs_field_6',
'table_zs_field_7',
'table_zs_field_8',
'table_zs_field_9',
'table_zs_field_10',
'table_zs_field_11',
'table_zs_field_12',
'table_zs_field_13',
'table_zs_field_14',
'table_zs_field_15',
'table_zs_field_16',
'table_zs_field_17',
'table_zs_field_18',
'table_zs_field_19',
],
]) ?>
If i write this to code I'll see a DetailView widget with names of fields(get from model) and values.
Problem: I want to hide values and show only names of fields from model and in next time hide names and show only values. Anybody know ?
Change the $template property of the Detailview.
The Default is
$template = '<tr><th>{label}</th><td>{value}</td></tr>'
Adding
'template'=>'<tr><th>{label}</th></tr>' ,
to the config array of your DetailView should show only the names of the fields.
Adding
'template'=>'<tr><td>{value}</td></tr>',
should show only the value.
See the corresponding section in the Documentation of DetailView.
Related
I have a base extension so i can version my website. That means i have not a controller or a repository on the extension. So what i want to do, is to create my own settings on existing elements. I was experimenting around with a text align values on the header content element.
Keep in mind, there is already a setting for this, but i am just
experimenting.
I figured out how to add them and the values are saved on the database.
What i now want to do, is to take the values and add them as a class on FLUID. This is where i stuck. I can not get the values. Any idea how to do it?
After this guide How to enable header_position in TYPO3 7.6
i manage to get my code that far:
On the folder /Configuration/TCA/Overrides/tt_content.php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position_custom' => [
'exclude' => 1,
'label' => 'header position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['left', 'left'],
['right', 'right'],
['center', 'center']
]
]
]
]);
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position_custom', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position_custom', 'after:header_layout');
On the folder /Configuration/Typoscript/Constants/Base.typoscript
styles.templates.templateRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Templates/
styles.templates.partialRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Partials/
styles.templates.layoutRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Layouts/
On the /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html
<h1 class="{positionClass} {header_position_custom} {data.header_position_custom} showed">
<f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>
I 've put the class showed just to make sure that i am reading the
file from the path i gave on the constants
File ext_tables.php
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Website Base');
File ext_tables.sql
CREATE TABLE tt_content (
header_position_custom varchar(255) DEFAULT '' NOT NULL,
);
With all these i get my selectbox where i wanted to be and i get the values on the database. That means that if i select the value "Center" in the selectbox, then it will be saved on the database. How can i get this value and use it as class on the FLUID?
Thanks in advance,
You will find your field in the data object.
For inspecting your fluid variables you can use the f:debug-VH:
<f:debug title="the data">{data}</f:debug>
for inspecting all (in the current context) available variables you can debug _all:
<f:debug title="all data">{_all}</f:debug>
Hint: use the title attribute to identify the output
and don't forget to write a get* and set* function for new fields!
I'm looking for a simple solution for a "checked" state for the Yii2 ActiveForm checkbox control and I can't find a solution how to set it. I cant find any examples in the documentation.
I've tried to manipulate the rendering code
<?php
echo $form->field($model, 'permissions[clients][view_all]')
->checkbox([
'uncheck'=>false,
'labelOptions' => [
'style' => 'padding-left:20px;'
]
])->label('View all');
?>
So how set activeChechbox to checked?
I was trying to show/hide ActionColumn based on some condition.
In my system, 2 roles are defined : Primary & Secondary. I wanted to hide ActionColumn for Role Secondary and to show ActionColumn for Role Primary.
I got one visible attribute option from $visible. Where, 'visible'=> true and 'visible'=> false are working properly.
<?
[
'class' => 'yii\grid\ActionColumn',
'visible' => false,
.
.
.
]
But, Problem is: I wanted to set visible option as True / False dynamically based on some condition.
<?
[
'class' => 'yii\grid\ActionColumn',
'visible' => function ($data) {
if (Yii::$app->userinfo->hasRole([AR::ROLE_PRIMARY])) {
return true;
}
if (Yii::$app->userinfo->hasRole([AR::ROLE_SECONDARY])) {
return false;
}
},
.
.
.
]
I tried in this way too. But, didn't got luck. Any help/hint/suggestion is appreciable.
I searched Yii2 GridView hide column conditionally.
You can't set visible to a callable, although there is nothing to stop you setting a variable before calling the gridview.
In this case though, visibility is only dependant on whether they have the primary role, you can just use:
'visible' => Yii::$app->userinfo->hasRole([AR::ROLE_PRIMARY])
You can use conditional statement to hide particular checkbox in grid view
Here is simple code which works for me
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($dataProvider) {
return ["value" => ($dataProvider['tiIsPaid'] == 0)?$dataProvider['iDriverEarningId']:'',"style"=>($dataProvider['tiIsPaid'] == 0)?'':'display:none'];},
]
Here i have used simple logic to hide checkbox for particular column
Set value null or blank so it can not be selected when you click on select all checkbox
Hide check box using display none property of css
Hope this help you in hiding particular column based on your conditions.
First of all i am working with yii2.0 framework.
Right, i have a gridview that pulls data from my database. It currently works and if i use any of the searches it will reload the page with the new data.
However i now have created some dropdownlist categories. Basically there are three tiers of categories , so a main category subcategory and child category. At the moment i have two ajax requests that will populate the sub and child category when the dropdownlist changes. (It populates the categories from my database).
Now i want the gridview to display the cases that are linked to the child categories. So when i choose my first category then choose my second and child category the gridview displays the content that relates to it.
At the moment my controller renders the searchModel + dataProvider for the grid view as seen below::
public function actionIndex()
{
$searchModel = new CaseSearch();
$allCategory = Category::find()->all();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'allCategory' => $allCategory
]);
}
and in my view it displays the data with this::
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'case_id',
'name',
'judgement_date',
'year',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
How should i go about achieving this? should i create something _grid.php which i can then render from my view and send the ajax request there?
The simplest way to achieve this functionality is to wrap the GridView with built-in Pjax widget like so:
use yii\widgets\Pjax;
<?php Pjax::begin(); ?>
// Place GridView code here
<?php Pjax::end(); ?>
From the js you can trigger form submit like that:
$('.grid-view-selector').yiiGridView('applyFilter');
If pjax is attached, content will be replaced dynamically without page reload.
Official docs:
Pjax
I would probably will use GridView $filterSelector.
And add the selector for youre custom category dropDown.
After you will need add category attribute for youre SearchModel.
In final - wou will get the filter with youre custom field added to standart some
been looking for a solution to add a feature for "Custom Columns"... Meaning, I present a list of columns that I can show the user and he selects the ones he wants to see and after the selection the table is updated and add/removes the needed columns.
Didn't find anything on Google (perhaps it has a different name than what I was looking for...)
Anyone has an Idea on how it can be accomplished?
Thanks in advance!
This is not a complete sample, but can give you some clues on how to implement it. You've to define some kind of form to collect the data about how your grid has to be rendered. I recommend you to create a CFormModel class if there are more than 3 input fields. Create a view file with the form and a div or renderPartial of a file containing a grid:
$form = $this->beginWidget('CActiveFormExt');
echo $form->errorSummary($model);
echo $form->labelEx($model,'column1');
echo $form->dropDownList($model
echo $form->error($model,'column1');
echo CHtml::ajaxSubmitButton('UpdateGrid',array('controller/grid'),
array('update'=>'#grid'),
$this->endWidget();
// you can render the 'default options' before any ajax update
$this->renderPartial('_grid',array($customColumns=>array('id','name'),'dataProvider'=>$dataProvider));
In the _grid.php view file:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'grid',
'dataProvider'=>$dataProvider,
'columns' => $customColumns;
));
In the controller:
function actionGrid(){
// recover the form data, and build the custom columns array
$customColumns = array();
$customColumns[] = '.....';
$dataProvider = ...;
$this->renderPartial('_formTrabajo', array('customColumns' => $idSiniestro, 'dataProvider' => $dataProvider'), false);
}
When you click the ajaxSubmitButton, the form is sent to the url specified through ajax, and the reply from the controller must contain the renderPartial of the view containing the grid, so the jQuery call can replace the html correctly. You must pass an array from your controller to the partial view of the grid, with the custom list of columns you want to display.