Home

Awesome

JsTreeBehavior

© 2013 Spiros Kabasakalis The MIT License (MIT)

JsTreeBehavior

LIVE DEMO

Overview

Tree graphic manipulation of an ActiveRecord with NestedSet Behavior using jstree plugin. This is actually a complete rewrite of my NestedSetAdminGUI extension. Instead of gii generated files for every model,I wrote a reusable behavior that provides the same functionality.I also have separated markup from js,and the code is much cleaner now.Many jstree options can be set in JsTreeWidget.php file,you can add more if you wish-I did'nt include them all,there are so many.

Setup.

public function behaviors()
{
  return array(
      'NestedSetBehavior'=>array(
          'class'=>'application.behaviors.NestedSetBehavior',
          'leftAttribute'=>'lft',
          'rightAttribute'=>'rgt',
          'levelAttribute'=>'level',
          'hasManyRoots'=>true
          ),
  );
}
 public function behaviors()
    {
        return array(
            'jsTreeBehavior' => array('class' => 'application.behaviors.JsTreeBehavior',
                'modelClassName' => 'Category',
                'form_alias_path' => 'application.views.category._form',
                'view_alias_path' => 'application.views.category.view',
                    'label_property' => 'name',
                    'rel_property' => 'name'
            )
        );
    }
$this->widget('application.widgets.JsTreeWidget',
                      array('modelClassName' => 'Category',
                                'jstree_container_ID' => 'Category-wrapper',//jstree will be rendered in this div.id of your choice.
                                'themes' => array('theme' => 'default', 'dots' => true, 'icons' => true),
                                'plugins' => array('themes', 'html_data', 'contextmenu', 'crrm', 'dnd', 'cookies', 'ui')
                                            ));
?>

Fot themes and plugins options see jtree documentation