2017-08-09 80 views
0

我已经DATATABLE与服务器端(MVC.net)分页,排序,过滤器柱和全局搜索如下数据表:了Serverside全局搜索不发送值“搜索[值] [0]”

的Html代码

<table id="Grid" class="dataTable table table-striped table-bordered " style="width: 100% !important"> 
     <thead> 
     <tr> 
      <th>Name</th> 
      <th>Name2</th> 
      <th>name3</th> 
      <th>name4</th> 
      <th>name5</th> 
      <th></th> 
      <th></th> 
      <th></th> 
      <th></th> 
      <th>last name</th> 

     </tr> 
     </thead> 
     <tbody> 
     </tbody> 
     <tfoot> 
     <tr> 
       <th> <input class="form-control texts" type="text" placeholder="Filter Name" id="filter0" maxlength="180" /></th> 
       <th> <input class="form-control texts" type="text" placeholder="Filter Host" id="filter1" maxlength="180" /></th> 
       <th> <select class="form-control selects" id="filter2"> 
        <option value="select">Select</option> 
        <option value="1">2</option> 
        <option value="2">2</option> 
       </select> </th> 
       <th> 
        <select class="form-control selects" id="filter3"> 
         <option value="select">Select</option> 
         <option value="1">true</option> 
         <option value="2">false/option> 
        </select> 
       </th> 
       <th><select class="form-control selects" id="filter4"> 
        <option value="select">Select</option> 
        <option value="True">True</option> 
        <option value="false">False</option> 
        </select> 
       </th> 
       <th> 
        <select class="form-control selects" id="filter5"> 
         <option value="select">Select</option> 
         <option value="True">True</option> 
         <option value="false">False</option> 
        </select> 
       </th> 
       <th></th> 
       <th></th> 
       <th> 
        <div class='input-group date col-xs-9' id="datepicker2"> 
         <input class="form-control datepicker texts" type="text" placeholder="Filter Key expiration date" id="filter8" maxlength="10" /> 
         <span class="input-group-addon"> 
          <span class="ebsi-icon-calendar"></span> 
         </span> 
        </div> 

       </th> 
       <th> 
        <div class="btn-group btn-group-xs pull-right"> 
         <input id="btnColumnFilters" class="datatable-action btn btn-sm btn-primary btn-secondary" type="button" value="Filter"/> 
         <input id="btnClearColumnFilters" class="datatable-action btn-sm btn btn-grey btn-secondary" type="button" value="Clear"/> 
        </div> 
       </th> 
      </tr> 
     <tfoot> 
    </table> 

javascript代码:

var ConfigTable = $('#Grid') 
       .on('preXhr.dt', function(e, settings, data) { 
        $(".alert").hide(); // hide any alerts 
       }) 
       .DataTable({ 
        autoWidth: true, 
        lengthChange: false, 
        responsive: true, 
        searching: true, 
        ordering: true, 
        paging: true, 
        pageLength: 10,      
        serverSide: true, 
        order: [[0, "asc"]], 
        ajax: { 
         url: "/controller/action", 
         type: "POST", 
         datatype: "json", 
         error: function (xhr, error, thrown) { 

         }, 
         data: function(d) { 
          return $.extend({}, 
           d, 
           { 
           }); 
         } 
        }, 
        columns: [ 
         { "data": "Name", "name": "Name", "autoWidth": true, "searchable": true }, 
         { "data": "Name2", "title": "Name2", "name": "Name2", "autoWidth": true, "searchable": true }..... 
        ] 
       }); 

按钮列过滤器单击

只有当用户点击进入或先前输入已被清除

$('#Grid_filter input').unbind(); 
$('#Grid_filter input').bind('keyup', function(e) { 
    if (e.keyCode == 13 || $(this).val() == "") { 
     // clear all filter selection 
     resetColumnFilters(); 
     //apply filters 
     ConfigTable.columns().search(this.value).draw(); 
    } 
}); 

服务器端代码

[HttpPost] 
      public JsonResult action(jQueryDataTableParamModel param) 
      { 
//globla filter     
var search = Request.Form.GetValues("search[value]")[0]; 
        // column filter 
var Name = Request.Form.GetValues("columns[0][search][value]")[0];   

      } 

,但我没有收到在“请求全局搜索值

//服务器端搜索。 Form.GetValues(“search [value]”)[0]“在服务器端。它总是以空字符串的形式出现。什么可能是这个问题,请帮助。

我正在使用1.10.2版本的数据表插件。

更新1:

签到萤火为AJAX请求的网络选项卡上,空字符串被发送用于搜索参数每个请求,即使搜索值是有

搜索[值]: “”

更新2: 如果我删除代码,只发送时,输入被击中全局过滤器值,它会将搜索值到服务器

更新3: 对this.value的警报给出了一个值,但是 ConfigTable.columns()。search(this.value).draw();不发送价值到服务器

+0

我不认为这是任何你添加的标签的问题。如果没有,您可能需要更改标签以获得更好的帮助 –

+0

感谢Darren,但它与jquery数据表插件有关。我不确定使用任何其他标签。 – amol

+0

很难分辨...我们可以在您的数据函数中获得console.log(d)吗? – Salketer

回答

0

找到解决方案。删除列(),同时发送全球过滤器

$('#Grid_filter input').bind('keyup', function(e) { 
    if (e.keyCode == 13 || $(this).val() == "") { 
     // clear all filter selection 
     resetColumnFilters(); 
     //removed columns() 
     ConfigTable.search(this.value).draw(); 
    } 
});