Google图表:单击节点链接导航到其他页面

时间:2018-12-11 11:39:18

标签: javascript google-visualization organizational-chart

您好,我在Codeigniter- PHP / Mysql中为我的Web应用程序使用了Google organisation charts。我已经从mysql数据库中加载了图表的节点。并将节点中的文本作为链接。到目前为止一切都很好。但是,现在我想将href添加到链接,以便当用户单击链接时,它应该导航到详细信息页面,其中显示了特定节点的详细信息。我知道,为了显示细节,应该有一个节点ID,以便从数据库中获取数据。 所以这是我的问题,如何将这个ID添加到链接中?

有没有办法做到这一点?谁能帮帮我吗。这是我的代码:

型号:

public function getTreeMembersData()
{
    $this->db->select('E1.name AS memname,E2.name AS parentname,E3.name AS spouse');
    $this->db->from('tab_members AS E1');
    $this->db->join('tab_members AS E2', 'E2.member_id = E1.parent_id','left outer');
    $this->db->join('tab_members AS E3', 'E3.parent_id = E1.member_id AND E3.relation_id = 3','left outer');
    $this->db->where('E1.relation_id !=', 3);
    $query = $this->db->get();
    return $query->result();
}

控制器:

public function membertree()
{
    if(isset($_SESSION['username']) || isset($_SESSION['userid']))
    {
        $page['pagename'] = "membertree";
        $data['msg'] = $this->session->flashdata('msg');
        $this->load->view('header',$page);
        $data['treedata'] = $this->Family_model->getTreeMembersData();
        $this->load->view('membertree',$data);
        $this->load->view('footer');
    }
    else
    {
        redirect('Auth/login');
    }
}

查看:

<script type="text/javascript">
    var url="<?php echo base_url();?>";
  google.charts.load('current', {packages:["orgchart"]});
  google.charts.setOnLoadCallback(drawChart);
    var data;
    var chart;

  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('string', 'Parent');

      data.addRows([<?php 
          foreach($treedata as $d)
          {  
              $memname = $d->memname;
              $parent = $d->parentname;
              $spouse = $d->spouse;
              ?>
          [{v:'<?php echo $memname;?>', f:'<a><?php echo $memname;?><a><div><a><?php echo $spouse;?></a></div>'},'<?php echo $parent; ?>'],
        <?php
          }
      ?>]);
      var options = {
                 'width':250,
                 'height':600};
    // Create the chart.
    var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
    // Draw the chart, setting the allowHtml option to true for the tooltips.
    chart.draw(data, {allowHtml:true});
      google.visualization.events.addListener(chart, 'select', selectHandler);

function selectHandler() {
  var selectedItem = chart.getSelection()[0];
if(selectedItem) {
    var name = data.getValue(selectedItem.row,0);
    alert(name);
 }
}
  }

  <div class="box">
    <div class="box-body">
            <div id="chart_div" class="chart"></div>
    </div>
   </div>

1 个答案:

答案 0 :(得分:1)

如果您能够从查询中获取ID,
您可以将地址作为'GET'属性中的href参数添加到详细信息页面。

类似...

<a href="http://address.to/details.php?id=<?php echo $id_field;?>"><?php echo $memname;?><a>

与数据行中一样

[{v:'<?php echo $memname;?>', f:'<a href="http://address.to/details.php?id=<?php echo $id_field;?>"><?php echo $memname;?><a><div><a><?php echo $spouse;?></a></div>'},'<?php echo $parent; ?>'],