【问题标题】:Using the CodeIgniter HTML Table Class, how can I add additional columns?使用 CodeIgniter HTML Table Class,如何添加额外的列?
【发布时间】:2011-03-10 16:57:18
【问题描述】:

添加行似乎很容易,但我想将列添加到具有复选框的数据中,以便您可以“编辑”或“删除”该行。

任何 CI 友好的方式来做到这一点?

【问题讨论】:

    标签: html codeigniter html-table


    【解决方案1】:

    手动设置标题和列,在最后一列中插入您需要的任何内容...

    $this->table->set_heading('Heading One', 'Heading Two', ... , 'Links'); //set your headings
    
    foreach($data_rows as $row) { //set your rows here
    
        // first build links for this row assuming you need the urls to
        // look like 'http://domain/index.php/controller/{action}/{id}
        $links  = anchor('controller/edit/'.$row->id ,'Edit');
        $links .= anchor('controller/delete/'.$row->id , 'Delete');
    
        $this->table->add_row(
            $row->heading_one,
            $row->heading_two,
            ...,
            $links,   //add the links you created to the last row, corresponding to your 'Links' Header
        );
    }
    
    echo $this->table->generate();
    

    【讨论】:

      【解决方案2】:
       **Error in code : Cannot use object of type mysqli as array in
       C:\xampp\htdocs\CodeIgniter-3.0.6\application\views\admin.php on line 8**
      <?php 
       $table_property = array('table_open' => '<table cellpadding="2" cellspacing="1" class="table table-hover">');
        $this->table->set_heading('#Id','Username','Password','Name','Edit','Delete');
        $this->table->set_template($table_property);
        $new=$this->db->query("select * from tbl_admin");
      
        foreach($new as $row) {
        $links  = anchor('admin/edit/'.$row['User_ID'] ,'Edit');
        $links .= anchor('admin/delete/'.$row['User_ID'] , 'Delete');
      
      
      $this->table->add_row(
          $row->User_ID,
          $row->Username,
          $row->Password,
          $row->Full_Name,
          $links
          );
      }
      echo $this->table->generate();
      

      ?>

      【讨论】:

      • 你能解释一下你的代码吗? (在您的答案中添加一些文字)此代码如何解决 OP 问题?代码的作用是什么?
      猜你喜欢
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多