kartik-v / yii2-tree-manager

An advanced tree management module using nested sets for Yii 2.
http://demos.krajee.com/tree-manager
Other
150 stars 107 forks source link

How to pass node id for each node clicked? #269

Closed fasi1208 closed 4 years ago

fasi1208 commented 4 years ago

I have multiple nodes. I want to show different views on each node click. For this, I have to pass the node id. Below is my code in which I have tried to explain the total scenario

   `<?=
   TreeView::widget([
    'query' => \common\models\MdcNode::find()->addOrderBy('root, lft'),
    'headingOptions' => ['label' => 'Root'],
    'rootOptions' => ['label'=>'<span class="text-primary">Root</span>'],
    'topRootAsHeading' => true, // this will override the headingOptions
    //'displayValue' => 1,        // initial display value
    'isAdmin' => false,
    'fontAwesome' => true,
    //'nodeView' => '',
    //show => none removes the iconType etc setting under details
    'iconEditSettings'=>['show'=>'none'],

    'toolbar' =>
        [
        TreeView::BTN_REFRESH => false,
        TreeView::BTN_CREATE => false,
        TreeView::BTN_CREATE_ROOT => false,
        TreeView::BTN_REMOVE => false,
        TreeView::BTN_SEPARATOR => false,
        TreeView::BTN_MOVE_UP => false,
        TreeView::BTN_MOVE_DOWN => false,
        TreeView::BTN_MOVE_LEFT => false,
        TreeView::BTN_MOVE_RIGHT => false,
    ],

    'showIDAttribute' => false,
    'showTooltips' => false,

    'showNameAttribute' => false,
    'softDelete' => false,
    'cacheSettings' => ['enableCache' => true],
    //removing the detail below removes the second column of view(s) 1 - 5. Section 5 is being used to render the extra data. See frontend\config\main.php later.
    'mainTemplate'=>'<div class="row">
                    <div class="col-sm-3">
                        {wrapper}
                    </div>
                    <div class="col-sm-9">
                        {detail}
                    </div>
                 </div>',
    'nodeAddlViews' => [
        Module::VIEW_PART_1 => '',
        Module::VIEW_PART_2 => '',
        Module::VIEW_PART_3 => '',
        Module::VIEW_PART_4 => '',
        Module::VIEW_PART_5 => '@backend/views/api/index',
    ]

]);
?>`

Controller

public function actionIndex() { echo "{Index}"; }

View

<?PHP
  /* @var $this yii\web\View */
  ?>

  <p>
    You may change the content of this page by modifying
    the file <code><?= __FILE__; ?></code>.
  </p>

UI

image

How can I pass each node id to my view when I click each node?

fasi1208 commented 4 years ago

Is there no one who can help me ? :(

kartik-v commented 4 years ago

This is done automatically via the extension via the ajax call - it passes the tree node model's key attribute via ajax call (check the jquery event treeview:selected) which then is used to find the tree node model and passed to the view.

You define which is the key attribute for the node model via the Module::dataStructure['keyAttribute'] setting - which defaults to id.