【问题标题】:Combine the aoData array from DataTables with the serliazed form将 DataTables 中的 aoData 数组与序列化形式相结合
【发布时间】:2015-07-18 05:26:39
【问题描述】:

我正在使用 jquery 数据表,并希望将 aoData 与使用 jquery 的表单序列化数据结合起来。

fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                    aoData.concat( $("#frm").serializeArray());
                    console.log(aoData);
                    $.ajax( {
                                                "dataType": 'json',
                                                "type": "POST",
                                                "url": 'sSource',
                                                "data": aoData,
                                                "success": fnCallback
                                              } );

}

但不合并,只返回数据表的数组响应。

你能帮我看看我们该怎么做吗?

谢谢

【问题讨论】:

    标签: php jquery datatables


    【解决方案1】:
     table_obj = $('#group-table').dataTable({
                    "sAjaxSource": "URL Goes HEre",
                    fnServerData: function(sSource, aoData, fnCallback,oSettings) {
    
                            aoData.push( $("#frm").serializeObject() );
    
                            console.log(aoData);
                            $.ajax( {
                                                        "dataType": 'json',
                                                        "type": "POST",
                                                        "url": sSource,
                                                        "data": aoData,
                                                        "success": fnCallback
                                                      } );
    
                    },
                    aaSorting: [[ 1, "desc" ]],
                    bProcessing: true,
                    bServerSide: true,
                    processing : true,
    
    
                    rowCallback: function(row, data, dataIndex){
                        // If row ID is in list of selected row IDs
                        if($.inArray(data[0], rows_selected) !== -1){
                           $(row).find('input[type="checkbox"]').prop('checked', true);
                           $(row).addClass('selected');
                        }
                    },
    
                    iDisplayLength: '50',
                });
    

    【讨论】:

      【解决方案2】:

      请尝试使用此代码并告诉我

      fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                              $.ajax( {
                                        "dataType": 'json',
                                        "type": "POST",
                                        "url": 'sSource',
                                        "data": $.merge(aoData, 
                                                $("#frm").serializeArray()),
                                        "success": fnCallback
                                                        } );
      
                                      }
      

      【讨论】:

      • 未正确组合...& 表单数据剩余...
        Array ( [sEcho] => 1 [iColumns] => 2 [sColumns] => , [iDisplayStart] => 0 [iDisplayLength] => 10 [mDataProp_0] => 0 [sSearch_0] => [bRegex_0] => 假 [bSearchable_0] => 假 [bSortable_0] => 假 [mDataProp_1] => 1 [sSearch_1] => [bRegex_1] => 假 [bSearchable_1] => 真 [bSortable_1] => 真 [sSearch] => [bRegex] => 假 [iSortCol_0] => 1 [sSortDir_0] => desc [iSortingCols] => 1 [未定义] => 
      • 不工作。变得相同..我认为我必须转换单个对象中的所有值而不是合并.. 像 Object { name="sSortDir_0", value="desc"} 而不是 (members_status[]=[2], source[]= [3]}
      • 如果你将所有的值组合成一个对象。表单值可能会与相同的索引值混淆。
      • 与其这样,不如转成json格式
      • 我尝试将数据转换为 json 格式。它已转换但未与数据表数据结合。
      【解决方案3】:
      table_obj = $('#group-table').dataTable({
                      "sAjaxSource": "URL Goes HEre",
                      fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                              $.ajax( {
                                                          "dataType": 'json',
                                                          "type": "POST",
                                                          "url": sSource,
                                                          "data": $.merge(aoData, $("#frm").serializeArray()),
                                                          "success": fnCallback
                                                        } );
      
                      },
                      aaSorting: [[ 1, "desc" ]],
                      bProcessing: true,
                      bServerSide: true,
                      processing : true,
      
      
                      rowCallback: function(row, data, dataIndex){
                          // If row ID is in list of selected row IDs
                          if($.inArray(data[0], rows_selected) !== -1){
                             $(row).find('input[type="checkbox"]').prop('checked', true);
                             $(row).addClass('selected');
                          }
                      },
      
                      iDisplayLength: '50',
                  });
      

      【讨论】:

      • 你不应该复制粘贴其他人的答案。
      猜你喜欢
      • 1970-01-01
      • 2020-04-30
      • 2020-01-26
      • 2019-05-20
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多