Modify Cgridview -> Template ->{Summary}

Hello. I want to modify {summary} in template of CGridView. Default summary display info looks like: {start} - {end} from {count}. For example i have records in my db, which are assigned to many users. I want to display "summary" like that: {count all records assigned only to actual logged user} - {count all observations in database}. Can anyone help me with this?

Many thanks

Tom

Hi,

you can something looklike this…


<?php 

widget('zii.widgets.CListView', array(

        'dataProvider'=>$dataProvider,

        'itemView'=>'_viewEvents',

        'summaryText'=> '{count all observations in database}', // to remove the

        'template'=>'{sorter}{pager}{summary}{items}{pager}{summary}{sorter}', // this code display pager, item, sorter etc

       //'template'=>'{items}', // to remove pager from the page use this code and remove above line

  

        'pager'=>array(

                'header'=>'',//text before it

                //page'=>'',

                'firstPageLabel'=>'',//overwrite firstPage lable

                'lastPageLabel'=>'',//overwrite lastPage lable

                'nextPageLabel'=>'',//overwrite nextPage lable

                'prevPageLabel'=>'',//overwrite prePage lable

        ),

    )); ?>

Hope it will be helpful…

Unfortunatelly it doesn’t work …

Thanks for help, but I think that You didn’t understand me, so i try to explain again what I was thinking about:

I want to modify {summary} in template of CGridView. Default summary display info which looks like: {start} - {end} from {count}. For example i have posts in my db, which are assigned to their authors by authors_id in Post model.

My post model:




Posts(id,title,content,authors_id, category_id)



I want to display lists of posts (in CGridVIew) of currently logged user with summary in CGridVIew header like: (count all posts of currently logged user)/(count all posts of all users in db). Additional, posts are assigned to categories(like: Cars, Home, Music, Books etc.) and if currently logged user is filtering (or search) his own posts by category (for example by Category Cars), then i want to display summary in CGridView like that: (count all posts of currently logged user from "Cars" category)/(count all posts of all users in db from "Cars" category"). I hope you understand me now:)

P.s. I don’t need to use CGridView {summary} field - i can use my own function to display that if this will be easier to do that.

P.s.2. sorry for my english :)

Tom:)

CGridView::$summaryText

Tsunami, i know that i have to use $summaryText, but how to enforce that sumamryText will show me statistic which i want ?

Sorry for my english:)

Tom

Well, the documentation shows which variables you can use, for everything else just use PHP.


$userPostsCount = Post::model()->count(array('user_id' => Yii::app()->user->id));


'summaryText' => $userPostsCount . ' of {count}',

Tsunami, i know this, but my problem is that additionaly, posts are assigned to categories(like: Cars, Home, Music, Books etc.) and if currently logged user is filtering (or search) his own posts by category (for example by Category Cars), then i want to display summary in CGridView like that: (count all posts of currently logged user from “Cars” category)/(count all posts of all users in db from “Cars” category"). I hope you understand me now:) Thanks for reply :)

i think you may use this change function.

first you can create the hidden field on top of the admin grid view and set the filter search value on hidden field and call this value on summaryText

for e.g…


<?php $gridId = 'wines-grid'; ?>




function updateGridAuto(val)

{

        var inputSelector = "#<?php echo $gridId?> .filters input, #<?php echo $gridId?> .filters select";

        $.fn.yiiGridView.update('<?php echo $gridId?>', {

        data:  $(inputSelector).serialize()

    });

}




$(document).ready(function(){

        $('#Wines_username_auto').change(function() {

                var val = $("#Wines_username").val($('#Wines_username_auto').val());

                updateGridAuto(val);

        });

});