jsTree tree widget for yii2.
Current state: unstable.
Created for use in DotPlant2 E-Commerce CMS.
Note: This package uses devgroup\JsTreeWidget
namespace.
In your controller(assuming it's backend/category
) add special action for retrieving Adjacency Tree:
public function actions()
{
return [
'getTree' => [
'class' => AdjacencyFullTreeDataAction::className(),
'class_name' => Category::className(),
'model_label_attribute' => 'name',
],
];
}
In your view file call the widget in the right place:
<?=
TreeWidget::widget([
'treeDataRoute' => ['/backend/category/getTree', 'selected_id' => $parent_id],
'contextMenuItems' => [
'open' => [
'label' => 'Open',
'action' => ContextMenuHelper::actionUrl(
['/backend/category/index'],
[
'parent_id',
]
),
],
'edit' => [
'label' => 'Edit',
'action' => ContextMenuHelper::actionUrl(
['/backend/category/edit']
),
]
],
]);
?>
TreeWidget
will register bundle JsTreeAssetBundle
, but you may want to include it as dependency in your main bundle(ie. for minification purpose).
ContextMenuHelper
creates JsExpression
for handling context menu option click. It automatically adds all data
attributes from item link(<a>
tag) if it is not specified exactly(as in 'open' menu item).