datatable ajax 发送数组中的数据值

datatable ajax send data values in array

我尝试使用 ajax/datable/codeigniter,我想在 post 中发送我的数据,例如数组数据(搜索['value'] = searched_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

使用数据 table 函数并将 datable 函数放在 javascript 下方的 html 中,将 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,因为现在有些功能在 datatables 的教程中无法使用。

Datables ver. 1.10

我的结果和我的第一个结果一样 post 只是改变 :

search [{
   'value' : searched_key
}]

来自

searched_key: searched_key

在你的控制器方法中定义:

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