【问题标题】:update button in datatable server-side数据表服务器端的更新按钮
【发布时间】:2018-04-11 09:31:17
【问题描述】:

我在 codeigniter 表中的视图中有这个表

<table id="#example">
 <thead>
  <tr>
   <th>ID</th>
   <th>EMRI</th>
   <th>MBIEMRI</th>
   <th>DEPARTAMENTI</th>
   <th>PUNA</th>
   <th></th>
  </tr>
 </thead>
</table>

我用 Jquery-PHP 数据库中的有效 JSON 数据填充它们。 为了识别行,我使用了 data-id=$row['id']

我如何从数据库中获取数据

foreach($result->result_array() as $row)
    {
        $sub_array = array();
        $sub_array[] = '<div contenteditable  data-id="'.$row["id"].'" data-column="emer">' . $row["id"] . '</div>';
        $sub_array[] = '<div contenteditable  data-id="'.$row["id"].'" data-column="emer">' . $row["emer"] . '</div>';
        $sub_array[] = '<div contenteditable  data-id="'.$row["id"].'" data-column="mbiemer">' . $row["mbiemer"] . '</div>';
        $sub_array[] = '<select contenteditable id="depedit" data-id="'.$row["id"].'" data-column="departament"><option value="'.$row["text"].'">' . $row["text"] . '</option></select>';
        $sub_array[] = '<select contenteditable id="jobedit" data-id="'.$row["id"].'" data-column="job"><option value="'.$row["text"].'">' . $row["text"] . '</option></select>';
        $sub_array[] = '<button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row["id"].'">Delete</button>
            <button type="button" name="update" class="btn btn-warning btn-xs update" id="'.$row["id"].'">Update</button>';
        $data[] = $sub_array;
    }


    $output = array(
    "draw"    => intval($_POST["draw"]),
    "recordsTotal"  =>  $rows,
    "recordsFiltered" => $number_filter_row,
    "data"    => $data
);

我想让更新按钮起作用。当我单击编辑按钮时,我想编辑该行的数据。

谁能帮帮我?

【问题讨论】:

  • 你想用ajax更新行吗?
  • 是的。我想让它对用户可编辑,然后对数据库进行更改。但是在数据库中进行更改很容易。我想让 jobedit 和 depedit 行选择不输入文本的表单。他们的数据应该由数据库中的数据填充。

标签: php jquery json database datatables


【解决方案1】:

首先为每一行添加一个类名,例如第一行:

<div class="firstRow" ... >...</div>
<div class="secondRow" ... >...</div>

然后你可以编辑JQuery中点击按钮的第一行:

$('button').click(function(){
    var id = $(this).attr('id');
    $('.firstRow[data-id='+id+']').text("My new text");
});

【讨论】:

  • 我想填充选择选项的数据。但我不能用 JQuery 填充它们,因为它们还不是 html 元素。它们是稍后添加的。当我尝试像 $("#jobedit") 一样获取它们时,它会返回一个错误。所以这是主要问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-09
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 2013-08-07
相关资源
最近更新 更多