jQuery DataTables过滤器undefined不是一个函数

时间:2015-03-14 09:46:39

标签: php jquery angularjs datatables fnfilter

我使用php生成表,然后使用jQuery DataTable对表进行过滤和排序:

function load_custumers_html(){

$sql_head = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'amitnet' AND TABLE_NAME = 'new_leads';";
$sql_body = "select * from new_leads;";

try {
    $db = getConnection1();
    $db1 = getConnection1();
    $stmt_head = $db->query($sql_head);
    $stmt_head1 = $db->query($sql_head);
    $stmt_head2 = $db->query($sql_head);
    $stmt_body = $db->query($sql_body);
    $colcount_head = $stmt_head->columnCount();
    $colcount_head1 = $stmt_head1->columnCount();
    $colcount_head2 = $stmt_head2->columnCount();
    $colcount_body = $stmt_body->columnCount();

    $data =  "<div style='clear: both;'></div>";
    $data .= "<table class='table table-striped table-hover table-condensed tablesorter tablesorter-header' id='new_customers'>";
    $data .= "    <thead>";

    $data .= "        <tr>";
    $J=0;
    while ($row = $stmt_head->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
        for ($i0=0; $i0 < $colcount_head; $i0++){
            $data .= "<th><select class='tselect$J' ></select><option value='0'> </option></th>";
            $J++;
        }
    }
    $data .= "        </tr>";

    $data .= "        <tr>";
    while ($row = $stmt_head1->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
        for ($ii=0; $ii < $colcount_head1 ;$ii++){
            $data .= "<th>$row[$ii]</th>";
        }
    }
    $data .= "        </tr>";
    $data .= "    </thead>";
    $data .= "    <tbody>";
    while ($row = $stmt_body->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
        $data .= "<tr>";
        for ($i=0; $i < $colcount_body; $i++){
            $data .= ($i == '0') ? "<td><a href='#/ncustomers/$row[$i]'>$row[$i]</a></td>" : "<td>$row[$i]</td>";
        }
        $data .= "</tr>";
    }
    $data .= "    </tbody>";
    $data .= "    <tfoot>";
    $data .= "        <tr>";
    $JJ=0;
    while ($row = $stmt_head2->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
        for ($ii=0; $ii < $colcount_head2 ;$ii++){
            $data .= ($JJ==0)? "<th>TEST</th>":"<th></th>";
            $JJ++;
        }
    }
    $data .= "        </tr>";
    $data .= "    </tfoot>";
    $data .= "</table>";
    $data .= "<script>$(document).ready(function() {
                var oTable =  $('#new_customers').DataTable({'language':{'url': 'db/Hebrew.json'},'Filter': true,'lengthMenu': [[10, 25, 50, -1], [10, 25, 50, 'הכל']],  'order': [[ 0, 'desc' ]],
                initComplete: function () {
                            var api = this.api();
                            api.columns().indexes().flatten().each( function ( i ) {
                                var tselect = '.tselect'+i;
                                var column = api.column( i );
                                $(tselect).append( '<option value=\"_\">_</option>' );
                                column.data().unique().sort().each( function ( d, j ) {
                                    if((i!=0)&&(i!=5)&&(i!=7)){
                                        $(tselect).append( '<option value=\"'+d+'\">'+d+'</option>' );
                                    }
                                });
                                $(tselect).change(function () {
                                    oTable.fnFilter('^'+$(this).val()+'$', i, false, false);
                                });
                            });
                        }
            });
            $('.table').on('click', 'tbody tr', function(event){ $(this).addClass('highlight').siblings().removeClass('highlight');});
            });</script>";
    echo $data;
    $db = null;
} catch (PDOException $e) {
    echo '{"error":{"text":' . $e->getMessage() . '}}';
}


}

每当我尝试过滤时,我一直得到一个未定义的错误,这不是一个引用以下内容的函数:

oTable.fnFilter('^'+$(this).val()+'$', i, false, false);

我在AngularJS旁边使用它,但是我的应用程序中没有出现错误,除了过滤器没有被触发的事实。

旁注,我正在为表头使用双行,一个显示从数据库中提取的列标题,另一个显示动态生成的过滤器(选择/下拉列表)。

有什么希望吗?

非常感谢任何帮助。

0 个答案:

没有答案