2016-09-23 2 views
0

JS에게 jQuery를 데이터 테이블에 매개 변수를 전달아약스의 사용자 정의 버튼을

내가 Ajax.I에 새로운 내가 작업을 선택할 수 있도록 버튼에 매개 변수를 전달해야의 RoR app.I에 대한 jQuery를 데이터 테이블을 한거야 버튼을 클릭 할 때 수행 할 작업.

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

그래,하지만 아약스 요청으로 매개 변수를 전달하는 방법은? – bharathisusi

관련 문제