2

CDE Pentaho 中的表组件基于数据表,我想在我的表中实现此功能https://datatables.net/examples/api/multi_filter.html

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
        var title = $('#example thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

    // DataTable
    var table = $('#example').DataTable();

    // Apply the search
    table.columns().eq( 0 ).each( function ( colIdx ) {
        $( 'input', table.column( colIdx ).footer() ).on( 'keyup change', function () {
            table
                .column( colIdx )
                .search( this.value )
                .draw();
        } );
    } );
} );

我无法让它工作,我收到错误处理组件消息,我尝试将它作为 js 片段,作为外部源,在后获取和后执行功能中包含,我认为每列缺少索引导致问题,我在输出选项中包含了索引,它也不起作用,

我还发现了这个替代方案http://jsfiddle.net/CmMfJ/2/#collaborate

var table = $('#example').DataTable();

$("#example tfoot th").each( function ( i ) {
  var select = $('<select><option value="">All</option></select>')
    .appendTo( $(this).empty() )
    .on( 'change', function () {
       var term =  $(this).val()!=='' ?   '^'+$(this).val()+'$' : '';
       table.column( i )
          .search(term, true, false )
          .draw();
       } );

  table.column( i ).data().unique().sort().each( function ( d, j ) {
    select.append( '<option value="'+d+'">'+d+'</option>' )
  });
});

我没有收到该代码的任何错误,但它不起作用,表没有改变,在这两种情况下在执行后函数中我这样做了:函数 f(){ 代码},我还更改了变量#example对于我的桌子的名称,没有任何效果,任何帮助将不胜感激,谢谢。

4

1 回答 1

0

您的 postExecution 方法可能是正确的方法,但您无法在该 div 上创建新的 DataTable。它已经被创建了。

如果您在 postExecution 执行期间检查 this 对象,则其中一个字段(不记得是哪个)使您可以访问 DataTable 对象(示例中的 var 表)。

于 2014-10-21T17:02:44.780 回答