我想显示一个jquery数据表,它有一个弹出框,所以我按照下面显示的方法控制器......但是这个没有用。问题在于add_column这种add_column的确切语法是什么。
function random()
{
$this->datatables
->select('c.first_name,o.id')
->from('orders as o')
->add_column(
echo anchor('admin/storedprod/cancel/`o.customer_user_id`', 'cancel', array('onClick' => "return confirm('Are you sure you want to delete?')"))
);
echo $this->datatables->generate();
}
答案 0 :(得分:0)
我建议你在两个单独的功能中执行此操作。
首先创建jquery数据表。
$(document).ready(function() {
$('#example').dataTable();
} );
创建你的表
echo ('<table id="example">');
echo ('<thead>');
echo ('<tr>');
echo ('<th>');
echo "First_name";
echo ('</th>');
echo ('<th>');
echo "Id";
echo ('</th>');
echo ('<th>');
echo "Delete";
echo ('</th>');
echo ('</tr>');
echo ('</thead>');
echo ('<tbody>');
foreach( ($data->user_info) as $row)
{
$first_name = $row['first_name'];
$user_id = $row['user_id'];
echo ('<tr>');
echo ('<td>');
echo ($first_name);
echo ('</td>');
echo ('<td>');
echo ($user_id);
echo ('</td>');
echo ('<td>');
echo "<button type="button" id= "delete">Delete</button>";
echo ('</td>');
echo('</tr>');
}
echo ('</tbody>');
echo ('</table>'); ?>
然后当您单击删除按钮时,您可以使用jquery ..
获取行ID$("#delete").live("click", function()
{
var id = $("td:first", this).text(); // This will get the first column value ( id )
msg = "You are going to delete this " ;
title = "Delete name ";
OK = "OK";
cancel = "COM_CANCEL";
$('#showmsg-content').html(msg);
$("#showmsg").dialog
({
modal: true,
title: title,
width: 550,
buttons:{
OK : function()
{
you can send the id to the model using ajax
$.ajax({
url: url,
async: false,
data: "&id=" + id ,
type : 'post',
success : function()
{
//row is deleted , refresh the page
$(this).dialog('close');
},
});
$(this).dialog('close');
},
cancel : function(){
$(this).dialog('close');
}
},
});
} );
这应该有效。我没试过这个..试一试..