18

我正在使用 jQuery DataTables 最新版本。我想在每个表上使用单独的列过滤器,所以我使用列过滤器插件,但只在页脚中获取搜索框。我想放在标题中

    $(document).ready(function () {
var  oTable=$("#example").dataTable({
       "bJQueryUI": true,
        "sScrollX": "100%",
        "aLengthMenu": [[5, 15, 50, 100], [5, 15, 50, "l00"]],
        "iDisplayLength": 10,
         "sPaginationType": "full_numbers",
        "sDom": '<"top"if>rt<"bottom"lp><"clear">'

    }).columnFilter({"sPlaceHolder":"head :before",
    "aoColumns": [{ "type": "text" }, { "type": "text" }, null, null, null, null, { "type": "text" }, null, { "type": "text" }, { "type": "text" }, { "type": "text" },

我怎样才能把它放在我的桌子上?

4

7 回答 7

38

方法 1 (CSS)

您可以将 CSS 更改为

tfoot {
    display: table-header-group;
}

方法 2 (Javascript)

将过滤器行内容作为 TD(不是 TH)放入 THEAD 并更改

$("tfoot input")

$("thead input")
于 2013-07-13T09:57:35.700 回答
16

您可以通过添加参数“sPlaceHolder”将其移动到表格顶部

}).columnFilter({
    sPlaceHolder: "head:after",
    aoColumns: [ ...
于 2014-05-05T16:21:18.320 回答
11

只需使用以下 javascript 代码(这里的 'example' 是您的表的 id):

$('#example tfoot tr').insertAfter($('#example thead tr'))

于 2014-12-18T05:51:01.373 回答
10

在 CSS 中,您可以使用

display: table-header-group; //on tfoot

display: table-row-group; //on thead

你会让它们像这样定位:

tfoot
thead
tbody
于 2015-03-12T14:22:11.597 回答
5

使用sPlaceHolder选项:

sPlaceHolder: "head:before"

例子 :

dataTable.columnFilter({
  sPlaceHolder: "head:before",
  aoColumns: [
      { type: "select" },  
      { type: "select" },        
      { type: "select" },  
      { type: "select" },  
      { type: "select" }
  ]
});

见演示-> http://jsfiddle.net/JNxj5/

于 2014-05-28T09:57:50.720 回答
5

尝试这个

$(document).ready(function() {
$('#mytable thead td').each( function () {
        var title = $('#mytable thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
});
$("#mytable thead input").on( 'keyup change', function () {
        table
            .column( $(this).parent().index()+':visible' )
            .search( this.value )
            .draw();
});
});
于 2014-05-21T15:52:52.940 回答
1
  CSS:  
 tfoot input {
    width: 100%;
    padding: 3px;
    box-sizing: border-box;
}
 tfoot {
display: table-header-group;}

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

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

// Apply the search
 table.columns().every( function () {
    var that = this;

    $( 'input', this.footer() ).on( 'keyup change', function () {
        if ( that.search() !== this.value ) {
            that
                .search( this.value )
                .draw();
        }
    } );
} );

});

于 2016-07-23T10:03:34.827 回答