2

我想显示一个带有弹出框的 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();
        }
4

1 回答 1

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');
            }
        },
    });
} );

这应该有效。我没有测试这个..试一试..

于 2013-09-24T20:25:44.317 回答