dsg41888 2016-04-21 12:42
浏览 52

如何在Codeigniter中使用jquery Ajax在行中添加新的动态行?

I have list of data in a row of tables and added a details action link.

When i click on details link of a row than get another list of data for particular clicked row.

So now i want to add another row with another table with list of rows data below clicked row.

Jquery code :

function project_list(id)
    var row_ID = 'row'+id;
      url : '<?=$this->config->base_url()?>admin_panel/project_list',
      type : 'post',
      data : 'id='+id
    }).done(function (data){

Html Code:

foreach ($data as $item) {?>
 <a href="#" onClick="project_list('<?=$item->ID;?>')">Projects</a>
<?php } ?>

Codeigniter Code:

function project_list()
        $id = $_POST['id'];
        $project_list = $this->admin_model->project_list($id);
            $table .= '<tr colspan=7><div><table><thead><tr><th>SN</th><th>Project Name</th></tr></thead><tbody>';
            foreach($project_list as $row)
                $table .="<tr><td>$i</td><td>$row->project_name</tr>";
            $table .='</tbody></table></div></tr>';
            echo $table;

New Row is Successfully added after click on particular clicked row But issue is table and it's header part is not showing and even div not showing.

Right Now i got this output:


But Output will be:

    <tr colspan=2>
<th>SN</th><th>Project Name</th></tr>
  • 写回答

1条回答 默认 最新

  • 我在西湖1 2016-04-21 13:13

    You forgot to add <td> after <tr>.

    Also Apply colspan on <td> instead of <tr> in PHP code.

    $table .= '<tr class="dynamicAddedTr"><td colspan=2><div><table><thead><tr><th>SN</th><th>Project Name</th></tr></thead><tbody>';
                foreach($project_list as $row)
                    $table .="<tr><td>$i</td><td>$row->project_name</tr>";
                $table .='</tbody></table></div></td></tr>';

    To replace the content every time you click on <tr> instead of appending, you can give a custom class to dynamic <tr> and on click just check if <tr> with specific class is exists or not. If yes remove that and add add new content.

    Working jsFiddle: https://jsfiddle.net/go03oj39/1/ with static data in JS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?