【问题标题】:datatable ajax send data values in arraydatatable ajax 在数组中发送数据值
【发布时间】:2017-08-18 15:40:59
【问题描述】:

我尝试使用 ajax/datable/codeigniter,并且我想在帖子中发送我的数据,例如数组数据 (search['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

【问题讨论】:

  • 你的问题是什么?
  • 搜索[{ 'value':searched_key }] 不工作

标签: ajax datatable codeigniter-2


【解决方案1】:

我的结果与我的第一篇文章相同,只是更改:

search [{
   'value' : searched_key
}]

通过

searched_key: searched_key

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

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

【讨论】:

    【解决方案2】:

    使用数据表函数并将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>'
              }
    
            ]
        }); 
    

    我会建议你使用最新的数据表,因为有些功能现在无法与数据表教程一起使用。

    Datables ver. 1.10

    【讨论】:

    • 我的问题只是在我的控制器方法中发送数据以获取 $_POST['search']['value'] 但它已经解决了,我只是像这样发送我的数据:“data”:{searched_jey :searched_key} 并在我的方法中定义 $_post['search']['value'] = $_post['searched_key'];
    • @ITS 你能上传你做的结果吗?对于未来的观众
    猜你喜欢
    • 1970-01-01
    • 2016-10-28
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 2021-01-07
    相关资源
    最近更新 更多