如何使用jQuery DataTables基于列值检索行?

Sco*_*ott 3 jquery datatables

有没有办法根据列值在jQuery DataTables中查找行?例如,我可以确定哪一行在第1列中包含值"foo"而在第2列中包含值"bar"吗?我想以编程方式确定哪一行包含这些值.简单地保留一个将值和行索引联系在一起的单独数据结构是最好的解决方案吗?我想删除包含给定值的列的表行.

我正在使用DataTables 1.8.0和jQuery 1.5.1.

glo*_*tho 6

我将使用fnGetData获取数据,遍历行并使用$ .inArray:

function getRow(table_id, arg1, arg2) {
    var oTable = $('#' + table_id).dataTable(),
        data = oTable.fnGetData(),
        row, i, l = data.length;

    for ( i = 0; i < l; i++ ) {
        row = data[i];

        // columns to search are hard-coded, but you could easily pass this in as well
        if ( $.inArray(arg1, row) == 0 && $.inArray(arg2, row) == 1 ) {
            return $('#' + table_id + ' tr').eq(i);
        }
    }
    return false;
}

$row = getRow('table_id', 'foo', 'bar');
Run Code Online (Sandbox Code Playgroud)

注意:未经测试