Hidden Pagination summary text - yii

I use CGridView in Yii to create tables.
I would like to show my table with pagination but hide the summary text at the top, which indicates the number of page restance (Displaying 1-4 of 4 results.)
Is that possible?
thank you
Sorry for my English

There is a template option. By default it equals {summary}\n{items}\n{pager}
If you override it in your gridview config, you'l be able to remove summary section:
$this->widget(
'zii.widgets.CGridView',
array(
Your options here ...
'template' => '{items}\n{pager}',
)
);

Another option is to set the CGridView summaryText value to false

Because YII uses CListView, it also add a certain summary class CSS in the asset folder. So to combat this, simply override the css.
Add this to your CSS.
#yw0>.summary{
display:none;
}

Related

Yii2 Gridview get all selected row for all pagination

I wrapped my gridview with Pjax widget like this
\yii\widgets\Pjax::begin();
gridview
\yii\widgets\Pjax::end();
in order to make the gridview make ajax request when I click on each pagination.
I also use ['class' => 'yii\grid\CheckboxColumn'], in column as well.
and I find that when I'm on first pagination I checked some rows and then go to second page and check some rows but when I go back to first page what I've checked is gone.
My question is how can I keep all checkedrow for all pagination
With current conditions (Pjax, multiple pages, yii\grid\CheckboxColumn) it's impossible because of the way it works.
When you click on the pagination links all GridView html content is replaced by new one that comes from the AJAX response.
So obviously all selected checkboxes on the previous page are gone.
Few possible ways to solve that:
1) Write custom javascript and server side logic.
As one of the options, you can send AJAX request to server with parameter meaning that user has chosen to select all data for the bulk delete operation (or use separate controller action for bulk deletion). In this case actually we don't need to get the selected data from user, because we can simply get them from database (credits - Seng).
2) Increase number of displayed rows per page.
3) Use infinite scroll extension, for example this.
4) Break desired action in several iterations:
select needed rows on first page, do action (for example, delete).
repeat this again for other pages.
You can get selected rows like that:
$('#your-grid-view').yiiGridView('getSelectedRows');
[infinite scroll] : http://kop.github.io/yii2-scroll-pager/ will work good if you do not have any pjax filters. If you have filters also in play, do not use this plugin as it does not support pjax filters with it. For rest of the applications it is perfect to use.
Update1 : it seems to be straight forward than expected, here is the how I accomplished it
Add following lines to the checkbox column
'checkboxOptions' => function($data){
return ['id' => $data->id, 'onClick' => 'selectedRow(this)'];
}
Now add following JS to the common js file you will have in your project of the page where this datagrid resides
var selectedItems=[]; //global variable
/**
* Store the value of the selected row or delete it if it is unselected
*
* #param {checkbox} ele
*/
function selectedRow(ele){
if($(ele).is(':checked')) {
//push the element
if(!selectedItems.includes($(ele).attr('id'))) {
selectedItems.push($(ele).attr('id'));
}
} else {
//pop the element
if(selectedItems.includes($(ele).attr('id'))) {
selectedItems.pop($(ele).attr('id'));
}
}
}
Above function will store the selected row ids in the global variable array
Now add following lines to pjax:end event handler
$(document).on('pjax:end', function () {
//Select the already selected items on the grid view
if(!empty(selectedItems)){
$.each(selectedItems, function (index,value) {
$("#"+value).attr('checked',true);
});
}
});
Hope it helps.
I just solved this problem and it works properly with Pjax.
You may use my CheckboxColumn. I hope this can help. The checked items are recorded with cookies.
You can read the part with //add by hezll to understand how to fix it, because I didn't provide a complete general one.
Hope it works for you.
https://owncloud.xiwangkt.com/index.php/s/dGH3fezC5MGCx4H

How to create dropdownlist with static and dynamic values in Asp.net MVC with a divider between them

I want to create a dropdownlist which have three static values: Select All, Text Only, Numeric only. After that I like to add a line with some padding (just to separate these options) and then add some dynamic options.
I am not sure how to do this, Can some body please help?
So far I have created a List<SelectListItem> in my view model, and populated the static values from BLL. But I am not sure how to add a divider line in the middle now, and append some dynamic options after that.
Thanks
The normal select tag will not work like that, you will have to create custom dropdown using spans or divs.
See some examples here:
http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/

How i dont display empty and null rows in yii

How I do not display empty and null rows in yiiframework with listview.
Many rows in database are null.When I want to show data in view.php I see many null rows.I see a data on the other page.
can I see just rows with data.
The CListView widget uses a template to render each row of data.
In the skeleton generated by Gii, the index.php file has a CListView widget that uses the _view.php file to display row data.
You only have to check if a field is null and don't show it.
If you are aking for the autogenerated view.php file, the default is CDetailView
At this place, you can use the "visible" element of the attribute item:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
array(
'name'=>'field1',
'visible'=>$model->field1!=null,
),
..............
See attributes property of CDetailView and CListView
in your model, put a condition to filter null/empty values before rendering the result to your view.
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('table_column', $this->tableColumn, false );
$criteria->condition .= "another_table_column IS NOT NULL"; //this will filter null values
Use the afterFind() method in your Model to change the value displayed in the view so that a null value is shown as "NA" or some other value like that.

How to specify page size in dynamically in yii view?

How to specify page size in dynamically in yii view?(not a grid view)
In my custom view page there is a search option to find list of users between 2 date
i need 2 know how to specify the page size dynamically? If number of rows less than 10 how to hide pagination ?
please check screen-shoot
I dont want the page navigation after search it confusing users..
my controller code
$criteria=new CDbCriteria();
$count=CustomerPayments::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$paymnt_details=CustomerPayments::model()->findAll($criteria);
$this->render('renewal',array('paymnt_details'=>$paymnt_details,'report'=>$report,'branch'=>$branch,'model'=>$model,'pages' => $pages,));
}
my view
Link
I'm assuming you want the entire list of search result be shown on a single page, no-matter how long it is?
If so, this is quite easy to achive.
As I can see in your code, you are now defining your pageSize to have a size of 10. You can update it to be dynamically be doing this:
$pages->pageSize = $count;
To remove the pagesizes you can change the css of your view file, but for that we would need your view file to see how you defined it.

Yii Cgridview Erases JS On Refresh

I'm using bootstrap and Bootstrap Editable extension in my GridView to edit data fast. It's awesome, but when I somehow refresh my gridview with AJAX (e.g. apply some fiter or delete a row) it dissapears from the page and if I want to edit-in-place again I have to refresh page manually (F5). This is how I apply editable plugin in my views/admin.php file:
Yii::app()->clientScript->registerScriptFile(
Yii::app()->assetManager->publish(
Yii::getPathOfAlias('ext.editable.assets.js').'/bootstrap-editable.min.js'
),
CClientScript::POS_HEAD
);
Yii::app()->clientScript->registerCssFile(
Yii::app()->assetManager->publish(
Yii::getPathOfAlias('ext.editable.assets.css').'/bootstrap-editable.css'
),
CClientScript::POS_HEAD
);
Yii::app()->clientScript->registerScript('editable', '$(".editable").editable();', CClientScript::POS_END);
Yii::app()->clientScript->registerCss('popover', '.popover{width: 600px !important;} .editable-popover{width: auto !important;}', CClientScript::POS_HEAD);
It's kind of messy, but I'm just trying to get it working.
Appreciate any help.
Try looking at http://www.yiiframework.com/doc/api/1.1/CGridView#afterAjaxUpdate-detail
ie.
'afterAjaxUpdate' => 'function() { $(".editable").editable(); }'