mctreegridview

A modification of cqtreeview,combining treeview and cgridview with filter search enabled
13 followers

this extension combines treeview in a gridview with a fully working filter search

Requirements

Yii 1.1 or above

Usage

1.Generate a model

  1. Add the widget to yourview

3.Download extension from downloads and upload into the extensions folder

//instead of zii.widgets.grid.CGridView a new extension CQTreeGridView is used here
$this->widget('ext.QTreeGridView.CQTreeGridView', array(
    'id'=>'category-grid',
    // 'cssFile'=>false,
    'ajaxUpdate' => false,
    'dataProvider'=>$dataProvider,
    'filter'=>$model,
    'columns'=>array(
        'id',
        'name',
        'description',
        //'icon',
        //'parent_id',
        array(
            'name' => 'parent_id',
            'value'=>'(($data->parent_id==0)?"No Parent" :$data->parentCategory->name)',
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{view}{update}{delete}',
            'buttons'=>array
            (
 
 
        ),
    ),
    ),
));

4.In your Controller

$model=new Category('search');
         $dataProvider=new CActiveDataProvider('Category');
 
         $criteria = new CDbCriteria();
 
        $model->unsetAttributes();  // clear any default values
        if(isset($_GET['Category']))
        {
 
               foreach($_GET['Category'] as $key=>$value) {
                    $criteria -> compare($key, $value, true, 'AND');
               }
               $dataProvider = new CActiveDataProvider('Category', array('criteria' => $criteria));
        }
 
        $this->render('admin',array(
            'model'=>$model,'dataProvider'=>$dataProvider
        ));

Resources

qtreeview extension original source in russian

Total 15 comments

#16770 report it
Revelis Luc Bonnin at 2014/03/26 08:49am
doesn't work

Doesn't work at all on non basic grid display. Too many hard coded piece of code :(

#15312 report it
howardEagle at 2013/10/27 08:46pm
Not correct when rows no ii order

If you will add nodes to parent in random order, grid will be incorrect. Try it yourself.

#13585 report it
shafi at 2013/06/08 09:40am
hi neil

is it worked for you..?.. it is the common form for all table with categories and sub categories.i m a newbie and i ll try to edit.thanks for ur comment..for the current need you please change the variable name inside extensions..

#13574 report it
AussieNeil at 2013/06/07 01:24am
Why assume that the key field is "id"

Very nice.

But why do you assume that the key field in a table is id? Line 48 Or that there is definitely going to be a field called parent_id. Line 49

Just my opinion but hardcoding values does not make this very flexible.

This should be more flexible so as to utilise the ability to set parameters. Even if you had an option that was 'id' -> 'somevariable' and 'parent_id' -> 'someothervariable' would make this much better.

Also an option to link tables rather have all the data in one table.

Neil

#13416 report it
salsero at 2013/05/28 06:57am
i will try it

i will try it... Thank's you!!!

#13415 report it
Stefano Mtangoo at 2013/05/28 06:18am
Thank you!

Its good extension but I was looking for something to organize my blog entries in dates and months like blogspot does. So as good as it is it is not suitable for that. So I might use it in future project not now. Thanks you for the work!

#13409 report it
shafi at 2013/05/28 02:14am
hi stifano

hi stefano slasero..is it ok for u...?...

#13395 report it
Stefano Mtangoo at 2013/05/27 06:28am
I see!

I see!

#13393 report it
shafi at 2013/05/27 05:48am
hi salsero

hi salsero , it willl work jus like you said...plz have a look at screenshots from downloads

#13392 report it
shafi at 2013/05/27 05:46am
yes

surely..it will work as you said...you can download screenshot from downloads...

#13391 report it
Stefano Mtangoo at 2013/05/27 05:38am
Demo

Any Demo?

#13388 report it
salsero at 2013/05/27 05:13am
if i understand

if i understand:

a) in the table i insert a row with (id=5) and (parent_id = null)

=> it is root;

b) in the table i insert a row with (id=6) and (parent_id = 5)

=> it will display as son of (a);

C) in the table i insert a row with (id=7) and (parent_id = 6)

=> it will display as son of (b);

is correct?

#13387 report it
shafi at 2013/05/27 04:49am
no need to specify levels now

thanks for your appreciation ...it will work as it is... nope!! there are no particular rules to build dataprovider...see the controller...

#13383 report it
salsero at 2013/05/27 03:21am
questions...

i really appreciate this extension but i have some questions: if my tree have 2 levels of depth, where do i specify it? there are particular rules to build dataprovider?

#13377 report it
shafi at 2013/05/26 01:35pm
plz comment

i m a newbie to yii..plz comment and hit thumbsup to improve myself...

Leave a comment

Please to leave your comment.

Create extension