2017-08-09 83 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(); 
    } 
});