datatable ajax在数组中发送数据值

时间:2017-08-18 15:40:59

标签: ajax datatable codeigniter-2

我尝试使用ajax / datable / codeigniter,我希望像数组数据一样发送我的数据(搜索[' value'] = searching_key)。

        function fetch_vtourdata( is_range_search, minPrice = '', maxPrice = '', minSurface = '', maxSurface = '', minNbRoom = '', maxNbRoom = '', searched_key = '')
        {
            var dataTable = $('#data_tableVtoursList').DataTable({
                "processing": true,
                "serverSide": true,
                "order": [],
                "ajax":{
                    url: "../../website/userVtourTable",
                    type: "POST",
                    data: { 'user_id': user_id,
                        // 1 = name of POST, 2 = values
                            is_range_search:is_range_search,
                            minPrice:minPrice,
                            maxPrice:maxPrice,
                            minSurface:minSurface,
                            maxSurface:maxSurface,
                            minNbRoom:minNbRoom,
                            maxNbRoom:maxNbRoom,
                            search[{
                                'value':searched_key
                            }] 
                          }
                },
                "columnDefs" : [
                    {
                        "target": [0, 3, 4],
                        "orderable": false,
                    }
                ]
            });

            $('#search').keyup(function(){
                dataTable.search($(this).val()).draw();
            });
        }

enter image description here

2 个答案:

答案 0 :(得分:1)

我的结果与我刚改变的第一篇文章相同:

search [{
   'value' : searched_key
}]

通过

searched_key: searched_key

在控制器方法中定义:

if ( isset( $_POST['searched_key'] ) && !empty( $_POST['searched_key'] ) ) {
     $_POST['search']['value'] = $_POST['searched_key'];    
}

答案 1 :(得分:0)

使用数据表函数并将datable dunction放在你的html下面的javascript中,在控制器中分隔ajax数据

您能否详细说明您的问题? 像这样

 var oTable = $('#example').DataTable({
        "ajax": "<?php echo base_url('dashboard/show_karyawan'); ?>",
        "bDestroy": true,
        "columns": [
           {
              "data": "id",
              render: function (data, type, row, meta) {
                  return meta.row + meta.settings._iDisplayStart + 1;
                 }
          },
            { "data": "NIP" },
            { "data": "nama" },
            { "data":"jabatan"},
          {
           "data": null, 
           "sDefaultContent": '<a href="" class="editor_view">view</a> / <a href="" class="editor_remove">Delete</a>'
          }

        ]
    }); 

我建议你使用最新的Datatables,因为现在有一些函数不能用于数据表教程。

Datables ver. 1.10