将参数传递给 jQuery 数据表中的 sAjaxSource [英] Passing arguments to sAjaxSource in jQuery datatables

查看:36
本文介绍了将参数传递给 jQuery 数据表中的 sAjaxSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CodeIgniter,但遇到以下问题.

I am working with CodeIgniter and I have the following problem.

我在 details.php 中有一个控制器函数,它接受一个参数:

I have a controller function in details.php which takes an argument:

function details($id) {
    $this->datatables
         ->select('product_id, original_amount, quantity')
         ->from('orders');

    echo $this->datatables->generate();
}  

现在我需要从视图中调用它,即我希望 DataTables 像这样显示它:

Now I need to call this from views, i.e. I want DataTables to display it like so:

<script>
$(document).ready(function() 
  $('#example').dataTable({
    ...
    'sAjaxSource' : 'admin/data/details',
    ...
  });
</script>

那么,如何将参数传递给 sAjaxSource 键,即 $id 变量?

So, how do I pass arguments to the sAjaxSource key, namely the $id variable?

推荐答案

您应该按照 文档.

You should use fnServerParams as specified in the docs.

$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "scripts/server_processing.php",
        "fnServerParams": function ( aoData ) {
            aoData.push( { "name": "more_data", "value": "my_value" } );
        }
    } );
} );

这篇关于将参数传递给 jQuery 数据表中的 sAjaxSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆