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;
}
Related
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'
]
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
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"
I have a Yii Layout, called Main, it loads all the CSS and the JavaScript, correctly ordered.
So, i have two views, one just have pure HTML, and the other one have something like this :
<?php
$dataProvider=new CActiveDataProvider('agenda');
$dataProvider->pagination->pageSize=5;
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'enablePagination'=>true,
'itemView'=>'_agenda', // refers to the partial view named '_agenda'
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'cssFile'=>'css/my.css',
),
));
?>
My problem :
The second one throw this exception Undefined is not a function and aim to the line with $(document).foundation(); in the code.
Is the only error it throws, and both have the same JavaScripts and CSS imported.
They are incompatible?
Solved, i just had conflicts with the Foundation's jQuery and Yii's jQuery.
The solution is just use this at top :
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
Remove others jQuery and move the foundation.min.js to the bottom.
I am dealing with the CGridView widget in Yii. I've customized most of it, but can't seem to customize the icons that appear when you click on the column headers to sort the data. (little arrows that point either up or down depending on the sort order) Also, the icons are completely gone after adding in the 'columns' option. A portion of the code in my view is below:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager' => array('cssFile' => '/css/myCss.css'),
'cssFile' => '/css/myCss.css',
'summaryText' => 'Showing {start} - {end} of {count} data rows.',
'htmlOptions' => array('id' => 'grid'),
'columns' => array(
array(
'name' => 'name',
'value' => '$data->name',
),
array(
'name' => 'description',
'value' => '$data->description',
),
array(
'name' => 'date',
'value' => '$data->date',
),
),
));
?>
Yii's documentation isn't clear at all on this and there doesn't seem to be anyone (that I could find) that also has this issue.
->Also, a related question:
How would I make each row an anchor link? I need each row to be a link to view the details about the clicked row. I know that cgridview provides view, edit, and delete links at the end of the row if told to, but is it possible to get the entire row to be a single anchor link? I know how to do this manually in html, but don't know how to do this inside cgridview.
If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid.
In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:
'columns'=>array(
...
array(
'name'=>'name',
'value'=>'CHtml::link($data->name, "#myAnchor")',
'type'=>'html'
),
...
)
I am not sure what version of Yii you're working on, but let's try this code
<?php
'columns' => array(
array(
...
'type' => 'html',
'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),