2017-08-09 4 views
0

の値を送信しませんコードDATATABLE:サーバー側グローバル検索は</p> <p>HTML形式を次のように私は、サーバー側(MVC.net)ページング、ソート、列フィルタとグローバル検索とデータテーブル持っている「[値]を検索[0]」で

<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リクエスト用のFirebugのネットワークタブでチェック、空の文字列が検索値があっても、検索パラメータの要求ごとに送信されている

検索[値]: 「」

アップデート2: 私はグローバルフィルタ値を送信するためのコードを削除すると入力しますがヒットした場合にのみ、それはサーバー

0123に検索値を送信

更新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(); 
    } 
}); 
関連する問題