jquery dataTables - 按范围排序

问题描述 投票:0回答:2

我有这个工作示例来排序包括列排序的表。

jsfiddle

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#searchresults thead tr').clone(true).appendTo( '#searchresults thead' );
    $('#searchresults thead tr:eq(1) th').each( function (i) {
        var title = $(this).text();
        // how to create 2 input fields to filter a range (e.g. filter rows where price ranges from 5 to 20)
        if (title == 'price') {
            // how can I do this ?
        }
        $(this).html( '<input type="text" />' );
        $( 'input', this ).on( 'keyup change', function () {
            if ( table.column(i).search() !== this.value ) {
                table
                    .column(i)
                    .search( this.value )
                    .draw();
            }
        } );
    } );
    var table = $('#searchresults').DataTable( {
        orderCellsTop: true,
        fixedHeader: true
    });
});

我想知道如何通过范围对列进行排序。在我的示例中,我希望“price”列有2个输入字段(“from”和“to”),以便仅显示表中价格为例如的项目。 5到20之间。

jquery datatables
2个回答
0
投票

你做了一个括号错误

qazxsw poi qazxsw poi qazxsw poi if ( (( isNaN( min_id ) && isNaN( max_id ) ) || ( isNaN( min_id ) && id <= max_id ) || ( min_id <= id && isNaN( max_id ) ) || ( min_id <= id && id <= max_id )) && (( isNaN( min_price ) && isNaN( max_price ) ) || ( isNaN( min_price ) && price <= max_price ) ||此外你需要更改id => min_vol,min_price && max_vol,max_price


0
投票

这是我的最终解决方案:( min_price <= price && isNaN( max_price ) ) ||

( min_price <= price   && price <= max_price ))
)

如果结果表有数百条记录,则输入时会有轻微的延迟。我想让这个更平滑一些。

© www.soinside.com 2019 - 2024. All rights reserved.