Yii2 custom pagination view - php

Hello everybody.
I need to do a custom pagination for the GridView.
In GridView I used:
'pager' => [
'prevPageLabel' => '<div style="border: none" class="glyphicon glyphicon-menu-left"></div>',
'nextPageLabel' => '<div style="border: none" class="glyphicon glyphicon-menu-right"></div>',
'maxButtonCount' => 0,
]
As a result, I get two arrows and then I can style them:
Question: How to put your own content between these arrows?
For example, I can get count of page: <?= $dataProvider->totalCount; ?> and I want to put this total count of pages between the arrows of pagination. How can I do this?Thanks!

You can extend LinkPager class, override renderPageButtons() to generate whatever content you like and then use this extended class in GridView configuration:
'pager' => [
'class' => 'new\extended\LinkPager'
]

Related

Customizing the Templates FormHelper for just plugins CakePHP 3?

I would like to customize a form helper template for just a plugin, not across the App.
Example: 'inputContainer' => '<div class="form-control">{{content}}</div>',
How do I go about doing this in CakePHP 3?
As per the docs - to change theme inline at runtime use setTemplate:
$myTemplates = [
'inputContainer' => '<div class="form-control">{{content}}</div>',
];
?>
<?= $this->Form->create('Users') ?>
<? $this->Form->setTemplates($myTemplates); ?>
<?=
$this->Form->input('email', [
'class' => 'form-control',
'templates' => [
'formGroup' => '{{input}}{{label}}'
]])
?>
You can't use the templates option on the Form for a dynamic template, it will only look for a config file listing template items in /config.

Date Picker Not working in yii2 Advanced

I am new to the Yii2 Advanced framework and am trying to insert a datepicker in an active form from a model.
I am using 2amigos widgets for date picker and updated my composer.json.
This is my code for Active Form
use dosamigos\datepicker\DatePicker;
<?= $form->field($model, 'user_date_birth')->widget(DatePicker::className(), [
// inline too, not bad
'inline' => true,
// modify template for custom rendering
'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
'clientOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);?>
but it does not show the datepicker on click and no errors are displayed.
How can I update my code to display the datepicker?
Nothing is wrong in your code ... but i think there is a problem in jquery .. add it in your AppAsset.php

How to disable few check boxes in a CheckBoxList in Yii?

I am using CHtml::checkBoxList in my Yii application. I need to disable few checkboxes based on some criteria. How can I do that using Yii itself?
Below is my code
echo CHtml::checkBoxList('sid','',$posts1, array('id'=>'1','template' => '{input}{label}</td></tr><tr><td width="10%" style="padding:0 0 10px 20px;" class="rbr">','checkAll' => 'All'));
This will generate a table similar to the image below
What I need is to disable the checkbox corresponding to the first row. i.e., the check box with 4X-B in its row.
Any help in this regard will be highly appreciated.
It is impossible using CHtml class. You can create custom Html class. Or use foreach to generate html.
create an Action as
public function actionIndex() {
$model= new CActiveDataProvider('ModelClass');
$this->render('index',array('model' => $model));
}
In Index.php view file
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model,
'columns' => array(
array(
'class' => 'CCheckBoxColumn',
'disabled' => '$data->last_column=="4X-B" ? true : false',
),
'country',
'last_column'
)
));
?>
Read CGridView

Yii2: How can I place something into a Breadcrumbs widget?

I find the Breadcrumbs widget quite useful. However, on the right side within the widget there is enough space for something else. If I'd like to put a link ('a' tag, but could be actually any other small thing) right aligned into the Breadcrumbs, how could I do that? What is a simple and proper solution? Should I extend the class, develop my own, use begin and end of the widget somehow?
If you look at yii\widgets\Breadcrumbs you see that there is a third parameter in the breadcrumbs items
From the Yii2 file
[
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "<li><b>{link}</b></li>\n", // template for this link only
],
So by adding something like this in your main layout file
$this->params['breadcrumbs'][] = [
'label' => 'Your Label',
'url' => ['controller/action'],
'template' => "<li style="float: right;">{link}</li>\n"
];
you will get a link at the right side. This link will come with a / prefixed, but you can bind it to a .class instead and configure it the way you want.
'template' => "<li class=\"yourClass\">{link}</li>\n"

Yii insert html in custom CListView

My problem: the two pagination options are on separate lines.
I have:
<div class="search_result searchconright">
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'dataProvider' => $model->search(),
'itemView' => '_index_post',
'enablePagination' => true,
'pager' => array(
'cssFile' => Yii::app()->baseUrl . '/css/clistview.css',
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'summaryText' => '',
'sortableAttributes' => array(
),
));
?>
</div>
<div class="pagetxt">
<span>View</span>
<a class="page_search_limit">All</a>
<a class="page_search_limit page_search_limit_active">3</a>
<a class="page_search_limit page_search_limit_active">5</a>
<a class="page_search_limit page_search_limit_active">24</a>
<a class="page_search_limit">48</a>
</div>
and i would like to insert the entire html from class pagetxt in the widget, because the seccond pagination, is under the widgets pagination; i would like them to be on the same line
also, other suggestions are welcomed
the pagination:
You have 2 options, first the way you are doing it, you can use the template property of CListView, to add the HTML where you want inside the widget.
But It looks like what you are trying to do, is to allow the user to specify the number of elements they want to see per page, so I'd recommend to use something like the PageSize extension
I think you can do this with CSS:
.search_result, .pagetxt {
display: inline-block;
}
To change the CListView pagination HTML, you would have to create a new CLinkPager and the pass parameters to it. So I think CSS is way simpler :)
This is purely a layout issue: you need to have the pager render inline with your custom HTML.
One way to do that would be to give display: line-block to both of these DIVs with CSS, but of course you can also use other techniques like floating.
You can easily target the stock pager by setting the pagerCssClass property on your list view; the default is simply "pager", so you could do
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'pagerCssClass' => 'pager pager-inline'
// ...
);
and then for example
.pager.pager-inline, .pagetxt {
display: inline-block;
}

Categories