数据:基于隐藏的列值隐藏行 [英] Datatables: Hide rows based on hidden column value

查看:130
本文介绍了数据:基于隐藏的列值隐藏行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dataTable 插件在jsp中显示我的表。我也想使用复选框选项。这样的东西

I am using dataTable plugin to display my table in jsp. I want to use check box option with it too. Something like here

DataTables:根据列中的值过滤行

在这种情况下,类型的值不会被隐藏。但在我的表中,第一列的值是隐藏的。在这种情况下如何编写JavaScript。

In this case the values of Types is not hidden. But in my table the value of first column is hidden. How to write JavaScript in that case.

我的数据表如下所示:

var userTable = $("#users").dataTable({
                    "sPaginationType": "full_numbers",
                    "bPaginate": true,
                    "bScrollCollapse": true,
                    "iDisplayLength": 10,
                    "bFilter": false,
                    "bJQueryUI": true,
                    "aoColumnDefs": [{ "bVisible": false, "aTargets": [0] }],

                });

只有当列值不被隐藏时,我才能使用链接中给出的解决方案。

I am able to use the solution given in the link only when the column values are not hidden.

function Clear() {    
    $('#users tr').show();}function Search(word) {
    Clear();
$('#users tr > td:first-child').each(function () {
        if ($(this).html() != word) {
             $(this).parent().hide();
        }
     });
}

我的标签如下所示:

<label>
  <input type="radio" name="RadioGroup1" value="radio1" id="radio1" onclick="Search('1')"/>
  Enabled</label>
<label>
  <input type="radio" name="RadioGroup1" value="radio2" id="radio2" onclick="Search('0')"/>
  Disabled</label>
  <label>
  <input type="radio" name="RadioGroup1" value="radio3" id="radio3" onclick="Clear()"/>
  All</label>


推荐答案

可以使用数据表的afnFiltering功能

You can use the afnFiltering functionality of datatables

$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
    var $radio = $("input[name='RadioGroup1']:checked").val();
    // show everything
    if ($radio == "all")
        return true;
    else // Filter column 1 where matches RadioGroup1.value
        return aData[0] == $radio;
});

http://jsfiddle.net/np8875Lm/1/

这篇关于数据:基于隐藏的列值隐藏行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆