数据表,过滤和绘图不会工作

时间:2016-11-04 05:23:14

标签: javascript jquery datatables

我尝试在点击按钮后添加过滤器。对我来说,它不会工作,我也不知道为什么。也许我的代码中有错误或被误解了?

结果,我得到一张空桌子。

在我的控制台中将出现错误" TypeError:table.ext未定义"

jQuery的:

     var table = $('#ajax_table1').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": $.fn.dataTable.pipeline( {
            url: 'data_kontakte.php',
            pages: 5 // number of pages to cache
        } ),
        "columnDefs":  [
            {
              "targets": 0,
              "data":    'type'
            },
            {
              "targets": 1,
              "data":    1
            },
            {
              "targets": 2,
              "data":    3
            },
            {
              "targets": 3,
              "data":    4
            },
            {
              "targets": 4,
              "data":    5
            },           
            {
              "targets": 5,
              "data":    'funcs'
            }             
            ],
        "drawCallback": function( settings ) {

          $('.tooltips').tooltip();

          //Confirmbox
          $('[data-toggle=confirmation]').confirmation({
            rootSelector: '[data-toggle=confirmation]',
          });
          //End Confirmbox

        },
        "language": {
               url: '../lang/<?php echo $_GET['lang'].'/'.$_GET['lang']; ?>.json'
         },
        // setup buttons extentension: http://datatables.net/extensions/buttons/
        buttons: [
                { extend: 'print', className: 'btn dark btn-outline' },
                { extend: 'pdf', className: 'btn green btn-outline' },
                { extend: 'csv', className: 'btn purple btn-outline' }
        ],
        "lengthMenu": [
                [5, 10, 15, 20, -1],
                [5, 10, 15, 20, "All"] // change per page values here
        ],
        //responsive: true,
        "bFilter": true,
        // set the initial value
        "pageLength": 10,


        //Layout
            "dom": "<'pull-left'f><'pull-right' B>r<'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>><'row'<'col-md-5 col-sm-12'l><'col-md-7 col-sm-12'>>",

        } );

//HERE IS THE FILTER_FUNCTION 
    $(document).on('click', '.related_contacts', function (event) {
            table.ext.search.push(
            function( settings, data, dataIndex ) {
                var min = parseInt( this.value , 10 );
                var max = parseInt( this.value , 10 );
                var resdata = parseFloat( data[1] ) || 0; // use data for the datatable column



                    if ( ( isNaN( min ) && isNaN( max ) ) ||
                     ( isNaN( min ) && resdata <= max ) ||
                     ( min <= resdata   && isNaN( max ) ) ||
                     ( min <= resdata   && resdatae <= max ) )
                {
                    return true;
                }
                return false;
            }
            ).draw();
        }); 

0 个答案:

没有答案