Yii customize CGridView Items template - yii

I am using Yii with bootstrap features;
So, I have changed the container tagName from div to table;
Now, the table with the items class is inside the table with table class;
The template property defines my issue;
How do I add the following class : table table-striped table-hover to the table with items class?
the tables structure is:
<table class="table">
<tr>
<td>
<table class="items">
...
{items} generates the <table class="items"> table
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'orders-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'ajaxUrl' => Yii::app()->baseUrl . '/orders/admin',
'tagName' => 'table',
'htmlOptions' => array(
'class' => 'table',
'style' => 'width:auto;',
'align' => 'left',
),
'cssFile' => Yii::app()->baseUrl . '/css/custom.css',
'template' =>
'<tr><td style="border-top:none;height:74px;">{pager}</td></tr>' .
'<tr><td style="height:34px;border-top:none;">{summary}</td></tr>' .
'<tr><td>{items}</td></tr>' .
'<tr><td style="border-top:none;">{summary}</td></tr>' .
'<tr><td style="border-top:none;height:74px;">{pager}</td></tr>',
'columns' => array(
array(
'header' => 'Order ID',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(str_pad($data->id, 9, "0", STR_PAD_LEFT),array("update","id"=>$data->id))',
),
array(
'header' => 'Name',
'name' => 'var_user_full_name',
'value' => '$data->UserFullName',
'filter' => CHtml::activeTextField($model, 'var_user_full_name'),
),
array(
'name' => 'total_price',
'type' => 'raw',
'value' => 'CurrencyData::$_currency[$data->currency]." ".$data->total_price',
),
array(
'name' => 'created',
'value' => 'date("d/m/Y",$data->created)',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'created',
'language' => 'en-AU',
// 'i18nScriptFile' => 'jquery.ui.datepicker-en.js',
'htmlOptions' => array(
'id' => 'datepicker_for_due_date',
'size' => '10',
),
'defaultOptions' => array(
'showOn' => 'focus',
'dateFormat' => 'dd/mm/yy',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
)
), true),
),
array(
'name' => 'active',
'header' => 'Status',
'value' => 'OrdersData::$active[$data->active]',
//'filter' => OrdersData::$active,
'filter' => CHtml::activeDropDownList($model, 'active', OrdersData::$active, array('prompt' => '-Select-')),
),
array(
'class' => 'CButtonColumn',
'header' => 'Action',
'template' => '{update}',
),
),
));
?>

found it:
'itemsCssClass' => 'table table-striped table-hover',

Related

hook with form Prestashop 1.7

guys (and ladies)
I like to ask you how to build the forms (formbuilder) in Prestashop 1.7 for the current 2020 year.
I created module with classes and hooks, but I can't find the info on how to create forms via "classes" and "controllers".
I'd happy to have something like this:
What have already done:
created custom module
created custom hook
custom .tpl from /module/templates/front/custom.tpl is added to the hook and displays data correctly.
Using form builder in your .php file (or controller)
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Live mode'),
'name' => 'TESTONE_LIVE_MODE',
'is_bool' => true,
'desc' => $this->l('Use this module in live mode'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'TESTONE_ACCOUNT_EMAIL',
'label' => $this->l('Email'),
),
array(
'type' => 'password',
'name' => 'TESTONE_ACCOUNT_PASSWORD',
'label' => $this->l('Password'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}

Add hidden values or insert values to fields that are not exposed to user when Using the HelperForm in PRESTASHOP 1.6.3

How to add hidden values or insert values to fields that are not exposed to user such as date_add and date_upd when Using the HelperForm class in PRESTASHOP 1.6.3
I created a new module and now there are two fields in my table which need to be inserted when a new add happens and when an update is done by the user but how to do this when I am using HelperForm class in PRESTASHOP
Below is my render form script
// This form is populated when add or edit is clicked
public function renderForm()
{
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
$ticketSeries = Winners::getTicketSeries();
$prdtCategory = Winners::getProductCategory();
$nationality = Winners::getNationality();
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Configure your Winner'),
'icon' => 'icon-user'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Ticket No'),
'name' => 'ticket_no',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'select',
'label' => $this->l('Ticket Series'),
'name' => 'series',
'required' => true,
'options' => array(
'query' => $ticketSeries,
'id' => 'ticket_series_name',
'name' => 'ticket_series_name'
),
'col' => '4',
'hint' => array(
$this->l('The ticket series of each draw !!.')
)
),
array(
'type' => 'select',
'label' => $this->l('Category'),
'name' => 'category',
'required' => true,
'options' => array(
'query' => $prdtCategory,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Product Category.')
)
),
array(
'type' => 'date',
'label' => $this->l('Draw Date:'),
'name' => 'draw_date',
'size' => 10,
'required' => true,
'desc' => $this->l('The draw date of this series'),
),
array(
'type' => 'select',
'label' => $this->l('Nationality'),
'name' => 'nationality',
'required' => true,
'options' => array(
'query' => $nationality,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Nationality the winner Belongs .')
)
),
array(
'type' => 'textarea',
'label' => $this->l('Testimonial'),
'name' => 'testimonial',
'required' => true,
'autoload_rte' => true,
'rows' => 7,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
), // add tag 'autoload_rte' => true, 'lang' => true, --> lang i removed
// since the editor value did not submit editor
)
);
//d(Tools::getIsset('update'));
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()##"°{}_$%:'
))
));
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$this->addJqueryUI('ui.datepicker');
return parent::renderForm();
}
I tried something like below yet no use
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()##"°{}_$%:'
))
));
use 'type' => 'hidden' and provide the value with, for example, 'value' => date("Y-m-d H:i:s")

Cannot do filtering via a dropdown menu in Yii TbGridView (v1.x.x)

I am trying to get the filtering to run although I am having some issues below is my view note that this in in a PARTIAL view :-
If I click on the header of the column it does the sorting as expected, however if I select an option from the dropdown it doesn't filter the items...
Any ideas?
<?php
$myuser = new Myuser('search');
$filterBtn = $this->widget('bootstrap.widgets.TbButton', array(
'icon' => 'filter',
'size' => 'small',
'label' => $myuser->paging ? 'View All' : 'View Less',
'htmlOptions' => array('class'=>'pull-right', 'style'=> 'margin:20px 0;'),
'url' => $myuser->paging ? array('/carrot/myuser/admin/paging/0') : array('/carrot/myuser/admin')
), true);
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'myuser-grid','type'=>'striped bordered condensed',
'dataProvider' => $myuser->search(),
'filter' => $myuser,
'columns' => array(
array(
'id' => 'user_id',
'class' => 'CCheckBoxColumn',
'checked' => 'in_array($data->user_id, $this->grid->owner->model->student_ids)',
'checkBoxHtmlOptions' => array(
'name' => 'selected_student_id[]',
)
),
'firstname',
'surname',
'username',
array(
'name' => 'year_id',
'filter' => CHtml::activeDropDownList($myuser, 'year_id', CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'), array('prompt'=>'All Years')),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::activeDropDownList($myuser, 'form_name', CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'), array('prompt'=>'All Forms')),
),
array(
'name' => 'House',
'filter' => CHtml::activeDropDownList($myuser, 'House', CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'), array('prompt'=>'All Houses')),
),
),
)); ?>
My model has the following search() method:
public function search($limit = false)
{
$criteria = new CDbCriteria();
$criteria->compare('t.user_id',$this->user_id,true);
$criteria->compare('t.firstname',$this->firstname,true);
$criteria->compare('t.surname',$this->surname,true);
$criteria->compare('t.username',$this->username,true);
$criteria->compare('t.year_id',$this->year_id);
$criteria->compare('t.form_name',$this->form_name);
$criteria->compare('t.House',$this->House);
$criteria->compare('o.organisation_id',$this->organisation_id);
$criteria->group = 't.user_id';
$criteria->together = true;
return new CActiveDataProvider($this->currentUserOrganisation(), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $this->paging ? ($limit) ? $limit : OverviewController::PAGE_SIZE : 2000
),
'sort' => array(
'defaultOrder' => array('firstname'=>false, 'surname'=>false),
'attributes' => array(
'organisation_name' => array(
'asc' => 'organisation_name',
'desc' => 'organisation_name DESC',
'default' => 'desc',
),
'*'
)
),
));
}
I think you can't use a DropDownList as filter, but you can easily use CHTML::listData():
array(
'name' => 'year_id',
'filter' => CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'),
),
array(
'name' => 'House',
'filter' => CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'),
),
This will automatically generate a DropDownList for you.
I hope this works for you.

YiiBooster Navbar target _blank

I am using the navbar of the extension Yiibooster, but I am having problems with a subitem of the menu, I need to go to a new tab, but I can't make it.
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => '<img src ="' . Yii::app()->request->baseUrl . '/images/FAVICON.png" />Inicio',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array('label' => 'Listado de Activos', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'itemOptions' => array('target' => '_blank')),
)),
If you want go to blank only in one item of the menu, this is the best option:
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array(
'label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'linkOptions' => array(
'target' => '_blank'
),
),
),
),
)
Yii CMenu docs: http://www.yiiframework.com/doc/api/1.1/CMenu#items-detail
add class=>'bootstrap.widgets.TbMenu' like
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'submenuOptions' => array('target' => '_blank'),
'items' => array(
array('label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
),
)
)
You need to use $brandOptions:
NavBar::begin([
'brandLabel' => 'Label text',
'brandUrl' => '/'.Yii::$app->homeUrl,
'brandOptions' => [
'target'=>'_blank'
],
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);

Yiibooster modal from navbar

I need to call my modal widget from a navbar using Yiibooster
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Inicio',
'fixed' => false,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => '#', 'active' => true),
array('label' => 'Filtro', 'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/create'),
)
)
)
)
));?>
htmlOptions doesnt work there, what can i do?
Use linkOptions instead of htmlOptions
...
array('label' => 'Filtro', 'linkOptions' => array('data-toggle' => 'modal','data-target' => '#myModal')),
...
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Zona Franca',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Inicio', 'url' => Yii::app()->baseUrl),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfArrendatarios/create'),
)),
array(
'class' => 'bootstrap.widgets.TbMenu',
'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
'items' => array(
array('label' => 'Filtro', 'url' => '#myModal'),
)),
)
)
)
;?>
There you have the answer :D