如何在codeigniter中使数据表标题动态化

时间:2017-09-12 09:30:44

标签: codeigniter datatable

  function list_datatable()
 {

    //function to initialize data table library
    $this->datatable_initialize();
    //set template for table        
    $tmpl = array ('table_open'  => '<table id="list_details"  class="table table-bordered responsive my_table table-striped">' );
    $this->table->set_template($tmpl); 
    //set  th heading for table     
    $this->table->set_heading('ID','Name','DOB','Email','Mobile','Address','Role'); 
    $this->table->set_caption('<colgroup> <col class="con0"> <col class="con1"><col class="con0"> <col class="con1">  <col class="con0"><col class="con1"><col class="con0"> </colgroup>');
}

我想用数据库查询动态设置数据表标题请帮我找一个解决方案

1 个答案:

答案 0 :(得分:0)

set_heading确实接受数组,而不是传递单个参数。因此,您可以将代码更改为

$this->table->set_heading("", $headingColumns);

$headingColumns是一个包含所有列名的数组,可以从数据库中获取。

您可以在此处找到更多信息:https://www.codeigniter.com/user_guide/libraries/table.html