DataTables - 点击" aLengthMenu"

时间:2018-06-06 14:38:19

标签: jquery datatables

我使用插件https://datatables.net/ 我想在aLengthMenu上添加onclick并在此处显示所选的值是我的代码:

$(document).ready(function() { 
 var oTable = $('# Table_id').DataTable({ 
         'iDisplayLength': '50', 
         "aLengthMenu": [ [20, 50, 100, 200], [20, 50, 100, 200] ]
        }); 
var oSettings = oTable.fnSettings(); 
var x = oSettings._iDisplayLength; });

1 个答案:

答案 0 :(得分:1)

您需要委派点击事件

<强> HTML

<table id="dataTable">...</table>

<强> JS

$(function() { 
     var oTable = $('#dataTable').DataTable({ 
         'iDisplayLength': '50', 
         "aLengthMenu": [
             [20, 50, 100, 200],
             [20, 50, 100, 200] 
         ]
     }); 
     var oSettings = oTable.fnSettings(); 
     var x = oSettings._iDisplayLength; 

    $(document).on("change", ".dataTables_length select", function(){
          var selectedVal = $(this).val();
          alert(selectedVal);
    });

});

<强> FIDDLE

http://jsfiddle.net/3jowrb4q/