I am trying to generate a Yii GridView using Bootstrap
On the ul element, i have the yiiPager class and i need to set it as the pagination class;
code here:
<h1>Manage Request Ms</h1>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'request-m-grid',
'type' => array('striped', 'bordered', 'condensed'),
'dataProvider' => $model->search(),
'template' => '{pager}{items}{pager}',
'filter' => $model,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
// 'class' => 'pagination',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
'rowCssClass' => 'pagination',
'columns' => array(
'id',
'domain_id',
'start',
'stop',
'delta1',
'delta2',
array(
'class' => 'CButtonColumn',
),
),
));
?>
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'request-m-grid',
....
'pager' => array('htmlOptions'=>array('class'=>'your_css_class')), // set whatever css class you want
));
Related
I wanna show data through CGridView with pagination..
Here the problem is that the dataprovider is an array ratherthan CArrayDataProvider or CDataProvider..
How to add pagination if dataprovider is an array as shown below
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-record-grid',
'dataProvider'=>$arr[1],
'enableSorting' => false,
'columns'=>
array()
));
You can try this CGridView in your view file.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-record-grid',
'dataProvider'=>$model->search(),
'afterAjaxUpdate' => 'function(){}',
'htmlOptions' => array('class' => 'form-inline', 'role' => 'grid'),
'ajaxUrl' => Yii::app()->createUrl('controllername/actioname'),
'ajaxUpdate' => true,
'enablePagination' => true,
"summaryText" => true,
'itemsCssClass' => 'responsive dataTable', // Item CSS Class
"template" => "{items}\n{summary}{pager}",
"summaryText" => "Showing {start} to {end} of {count} entries",
'pagerCssClass' => '', // Page CSS Class
'pager' => array(
'class' => 'CLinkPager',
'maxButtonCount' => 5,
'nextPageLabel' => 'Next',
'prevPageLabel' => 'Prev',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'selectableRows' => 2,
'enableSorting' => false,
'columns'=>array()
)
);
I'm trying to set up a new grid view in yii booster while passing a variable through at the start of the view to sort the formatting.
I presume I am not passing the variable properly by this line
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
How would I go about using this variable? I can create a new form array okay not using yiibooster but with the widget activated it no longer likes the variable name
The issue is I'm getting the error in the title of the post.
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
'id' => 'delegate-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
// 'id',
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
// 'facilities',
// 'telephone',
// 'address_id',
/*
'logo_path',
*/
array(
'class' => 'booster.widgets.TbButtonColumn',
),
),
));
$groupGridColumns = $gridColumns;
$groupGridColumns[] = array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
);
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
//'template' => "{items}",
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => $groupGridColumns,
));
It is because you are giving an object of type CGridView to TbGroupGridView as parameter.
$groupGridColumns = $gridColumns;
You are putting an object of type TbGridView($gridColumns) in $groupGridColumns and then give it to your TbGroupGridView, but TbGroupGridView columns property expects its value be an array of arrays(definition of columns) and so throws new exception when in the first cell of $groupGridColumns find an object.
You do not need the first part and with some changes, your code should work fine with filtering enabled.
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => array(
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
)
array(
'class' => 'booster.widgets.TbButtonColumn',
),
)
));
Here is my code
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'dsfsd',
'dataProvider' => $model->search(),
'filter' => $model,
'cssFile' => false,
'itemsCssClass' => 'table table-striped',
'beforeAjaxUpdate'=>'js:function(id,options){$.blockUI({
message: "Please wait",
//showOverlay: false,
css: {
border: "none",
padding: "15px",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 1,
"z-index": "9999"
}
});}',
'columns' => array(
array(
'header' => '#',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->id),array("abc/m/".CHtml::encode($data->id)."/info"))',
'htmlOptions' => array('width' => '40px'),
'filter' => CHtml::activeTextField($model, 'id', array('placeholder' => 'search by id')),
), array(
'header' => 'First name',
'name' => '$data.user.f_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->f_name)',
), array(
'header' => 'Last name',
'name' => '$data.user.l_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->l_name)'
),
array(
'class' => 'CButtonColumn',
'template' => '{update} {delete}',
//'updateButtonUrl' => 'Yii::app()->createUrl("abc/xyz?id=".$data->id."&c_id=".$data->c_id)',
'deleteButtonUrl' => 'Yii::app()->createUrl("xyv/abc",array("uid"=>$data->id))',
),
),
));
Well, what I want is that the operations under beforeAjaxUpdate will work only when delete button is clicked, not for any other ajax actions like on search or update. How is it possible?
You can add callback function to delete button:
http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail
You should set click option in buttons config array:
'columns' => array(
...
'buttons'=>array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',
'buttons'=>array(
'delete'=>array(
'click'=>'function(){/*your code here*/}'
)
)
)
...
)
You can return false from callback function to prevent deleting.
I have installed in Yii 1.1
$this->widget('zii.widgets.CListView', array(
'template' => Yii::t('Site','Header News')
But how 'to do it in Yii2 ?
echo ListView::widget(['template' => Yii::t('Site','Header News'),
'dataProvider' => $tipsList,
'itemView' => '_listItem',
'layout' => '{items}{pager}',
'itemOptions' => [
],
'options' => [
'links' => '<h2>test</h2>',
'tag' => 'ul',
'class' => 'ten-vertical summary-list',
],
'viewParams' => array(
'categoryAlias' => $categories[0]->urlAlias,
'imageConfig' => array('width' => 120, 'height' => 120, 'fill' => true),
'firstImageConfig' => array('width' => 436, 'height' => 436, 'fill' => true),
),
]);
Param 'template' => Yii::t('Site','Header News') does not work
template property of ListView in Yii2 called layout. Link
Example:
'layout' => '<li class="list-header">Header</li>{items}{pager}',
'options' => [
'tag' => 'ul',
],
The li.list-header will be added into a parent tag ul
I am using Yii Rights modules for ACL where I want pagination for Permissions page.
Following is my code:
In AuthItemController.php
public function actionPermissions() {
$dataProvider = new RPermissionDataProvider('permissions', array(
'pagination' => array(
'pageSize' => 10,
//'class' => 'CPagination', //showing an error
'itemCount' => 32
)));
// Get the roles from the data provider
$roles = $dataProvider->getRoles();
$roleColumnWidth = $roles !== array() ? 75 / count($roles) : 0;
// Initialize the columns
$columns = array(
array(
'name' => 'description',
'header' => Rights::t('core', 'Item'),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'permission-column',
'style' => 'width:25%',
),
),
);
// Add a column for each role
foreach ($roles as $roleName => $role) {
$columns[] = array(
'name' => strtolower($roleName),
'header' => $role->getNameText(),
'type' => 'raw',
'htmlOptions' => array(
'class' => 'role-column',
'style' => 'width:' . $roleColumnWidth . '%',
),
);
}
$view = 'permissions';
$params = array(
'dataProvider' => $dataProvider,
'columns' => $columns,
);
// Render the view
isset($_POST['ajax']) === true ? $this->renderPartial($view, $params) : $this->render($view, $params);
}
And in View
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'bordered',
'dataProvider' => $dataProvider,
'template' => '{pager}{items}',
'emptyText' => Rights::t('core', 'No authorization items found.'),
'htmlOptions' => array('class' => 'grid-view permission-table'),
'columns' => $columns,
'pager' => array(
'header' => '',
'hiddenPageCssClass' => 'disabled',
'maxButtonCount' => 3,
'cssFile' => false,
'class' => 'CLinkPager',
'prevPageLabel' => '<i class="icon-chevron-left"></i>',
'nextPageLabel' => '<i class="icon-chevron-right"></i>',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
),
'pagerCssClass' => 'pagination',
));
I have already implemented pagination for other pages by using same method but here in rights module its not working. Its not showing any error but also not displaying pagination links/buttons.
I had the same problem when implementing multiple grids in one page, the solution that worked for me was , I checked the url the grid ajax call,and before update I manipulated the url, and set the correct url and parameters before ajax request!
like:
$this->widget('zii.grid.GridView', array(
'id' => 'group-grid-customers-list-not-scheduled',
'dataProvider' => $notScheduledVisitedDataProvider ,
'beforeAjaxUpdate' => '
function(id , options)
{
options.url = options.url.split("&test=test&");
options.url = options.url[0] + "&test=test&" + $(".search-form form").serialize();
}',
'columns' => array(
'col1',
'col2',
'col3',
),
));