DataTables在特定列中进行单独搜索(文本输入)

时间:2018-08-01 08:33:16

标签: jquery datatables

找到了解决方案:

('#tabla_diccionarios tfoot th').each( function () {
    var title = $(this).text();
    if(title=="Key" || title=="Nombre")
        $(this).html( '<input type="text" />' );
} );

初始帖子

我需要在特定的列中进行搜索,图像如下: table header & search photo

仅在名为“ Key”和“ Nombre”的列中

这是我的代码

var table = $('#tabla_diccionarios').DataTable( {
    "pagingType": "simple_numbers",
    "language": "json",
    "lengthMenu": [[-1, 10, 25, 50], ["Todos", 10, 25, 50]],
    "language": {
        "lengthMenu": "Mostrar registros _MENU_ ",
        "zeroRecords": "No se encontraron resultados.",
        "info": "Mostrando registros del _START_ al _END_ de un total de 
_TOTAL_ registros.",
        "infoEmpty": "No hay registros disponibles",
        "infoFiltered": "(filtrado de un total de _MAX_ registros)",
        "paginate": {
            "previous": "Anterior",
            "next": "Siguiente",
        },
        "search": "Buscar: ",
    }
});

$('#tabla_diccionarios tfoot th').each( function () {
    /* var title = $(this).text(); */
    $(this).html( '<input type="text" />' );
} );

// 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();
        }
    } );
} );   

我该怎么做? 谢谢!

1 个答案:

答案 0 :(得分:1)

只需弄清楚:

('#tabla_diccionarios tfoot th').each( function () {
    var title = $(this).text();
    if(title=="Key" || title=="Nombre")
        $(this).html( '<input type="text" />' );
} );