2017-04-06 1 views
0

DataTables를 사용하여 테이블에 데이터를로드합니다. 데이터가 너무 커서 서버 측 처리가 잘 작동합니다. 그러나, 나는 내 아약스 호출에 사용자 지정 매개 변수를 전달하는 방법을 잘 모르겠습니다.datatables.js에 사용자 지정 매개 변수 전달

여러 매개 변수 (다른 매개 변수에 대해 다른 버튼)를 사용하려면 어떻게해야합니까? 이것은이 예에서 기반

<script> 
$.fn.dataTable.ext.buttons.reload = { 
text: 'Reload', 
action: function (e, dt, node, config) { 
    dt.ajax.reload(); 
} 
}; 


    $(document).ready(function() { 
     $('#landing_pages').DataTable({ 
      dom: 'Blfrtip', 
      keys: true, 
      deferRender: true, 
      responsive: true, 
      "searching": false, 
      "lengthMenu": [[10, 25, 50, 500], [10, 25, 50, 500]], 
      buttons: [ 
       'copy', 'csv', 'excel', 'pdf', 'print', 'reload' 
      ], 
      "processing": true, 
      "serverSide": true, 
      "ajax":{'url': "/data-source/landing-pages/{{profile_id}}{{page_dim}}", "data": function (d) { 
      d.myKey = "myValue"; 
      // d.custom = $('#myInput').val(); 
      // etc 
     }} 

     }); 
    }); 
    </script> 

: https://datatables.net/examples/server_side/custom_vars.html

답변

0

한 가지 방법은 다음의 데이터 테이블을 파괴 원하는 매개 변수를 다시 초기화하는 것입니다 여기에

는 지금까지 내 코드입니다. 다음과 같이 입력하십시오 :

$.fn.dataTable.ext.buttons.reload = { 
text: 'Reload', 
action: function (e, dt, node, config) { 

    // Get the profile_id and page_dim values to pass in to the initializer 

    // Destroy the datatable 
    $("#MyTable").dataTable().fnDestroy(); 
    // reinitialize the datatable with the new call with the variables 
    InitializeTable(profile_id, page_dim); 
} 
}; 

function InitializeTable(profile_id, page_dim) { 

    var initTable = { 
     dom: 'Blfrtip', 
      keys: true, 
      deferRender: true, 
      responsive: true, 
      "searching": false, 
      "lengthMenu": [[10, 25, 50, 500], [10, 25, 50, 500]], 
      buttons: [ 
       'copy', 'csv', 'excel', 'pdf', 'print', 'reload' 
      ], 
      "processing": true, 
      "serverSide": true, 
      "ajax":{'url': "/data-source/landing-pages/" + profile_id + "/" + page_dim, "data": function (d) { 
      d.myKey = "myValue"; 
    }; 

    // Initialize the data table with the parameters above 
    $("#MyTable").dataTable(initTable); 
} 
+0

감사합니다. 그렇다면 여러 사람에게 어떻게해야합니까? – Adders

+0

여러 번? 테이블? 테이블의 경우 초기화 할 각 테이블에 대한 함수를 작성하십시오. 각 테이블에는 자체 Ajax 호출 및 매개 변수가 있습니다. – Simon

+0

매개 변수가 없습니다. 확실하지 않은 것이 있으면 미안합니다. – Adders

관련 문제