2016-09-23 5 views
0

JSにjQueryのDataTableのパラメータを渡すAjaxのカスタムボタンは

私はAjax.Iに新しい、私はアクションを選択できるようにボタンにパラメータを渡す必要がRoRのapp.IのためのjQueryのdataTableをしていますよボタンがクリックされたときに実行される。

var invoiceTable = $('#invoice_list_index').DataTable({ 
 
    "scrollY": "300px", 
 
    "bScrollCollapse": true, 
 
    processing: true, 
 
    serverSide: true, 
 
    dom: 'Bfrtip', 
 
     buttons: [ 
 
      { 
 
       extend: 'alert', 
 
       text: 'My button 1', 
 
      }, 
 
      { 
 
       extend: 'alert', 
 
       text: 'My button 2' 
 
      }, 
 
      { 
 
       extend: 'alert', 
 
       text: 'My button 3' 
 
      } 
 
     ], 
 
    "ajax": { 
 
     type: "POST", 
 
     url: '/invoices/invoice_index_page', 
 
     
 
    } 
 
    });
<a class="dt-button buttons-alert" tabindex="0" aria-controls="invoice_list_index" href="#"><span>My button 1</span></a>

問題は、私はアヤックスカスタムボタンにパラメータを渡す方法がわからないです。

+0

これらのボタンのアクションにはどのようなパラメータを渡しますか?それらのテーブルの行のデータですか? –

答えて

0

jQueryが含まれているかどうかを確認してください。

0

デモ:あなたがする必要があるhttps://jsfiddle.net/Prakash_Thete/7v7xLaz2/1/

まあ最初の事はあなたのDataTable buttonsのためのアクションを作成することです。

以下のようにボタンを作成してください。

"dom": 'Bfrtip', 
    "buttons": [ 
      { 
       text: 'My button 1', 
       action: function() { 
       console.log("inside button 1"); 
       } 
      }, 
      { 
       text: 'My button 2', 
       action: function() { 
       console.log("inside button 2"); 
       } 
      }, 
      { 
       text: 'My button 3', 
       action: function() { 
       console.log("inside button 3"); 
       } 
      } 
     ] 

ボタンをクリックすると、対応するメッセージが表示されます。

これらのボタンにパラメータを渡すことは、他の通常のボタンと同じように、対応するボタンのアクション内の変数を使用するだけです。

+0

大丈夫ですが、どのようにAjaxリクエストでパラメータを渡すのですか? – bharathisusi