【问题标题】:Hide a column in datatable隐藏数据表中的列
【发布时间】:2018-08-13 08:28:10
【问题描述】:

我有一个问题,我想在数据表中隐藏列,但仍需要访问其值。

这是我的代码

<div class="container">
  <div class="">
    <h1>HRphn</h1>
    <div class="col-sm-8">
    <div class="well clearfix">
        <div class="pull-right"><button type="button" class="btn btn-xs btn-primary" id="command-add" data-row-id="0">
        <span class="glyphicon glyphicon-plus"></span> Record</button></div></div>
    <table id="posting_grid" class="table table-condensed table-hover table-striped" width="60%" cellspacing="0" data-toggle="bootgrid">
        <thead>
            <tr>
                <th data-column-id="id" data-type="numeric" data-identifier="true">Posting No</th>
                <th data-column-id="position">Position</th>
                <th data-column-id="department">Department</th>
                <th data-column-id="vacancy">Vacancy</th>
                <th data-column-id="postingdate">Date</th>
                <th data-column-id="status">Status</th>
                <th data-column-id="qualification" clas="hidden-lg"></th>
                <th data-column-id="experience" class="hidden-lg"></th>
                <th data-column-id="criteria1" class="hidden-lg"></th>
                <th data-column-id="criteria2" class="hidden-lg"></th>
                <th data-column-id="criteria3" class="hidden-lg"></th>
                <th data-column-id="jd1" ></th>
                <th data-column-id="jd2" ></th>
                <th data-column-id="jd3" ></th>
                <th data-column-id="jd4" ></th>
                <th data-column-id="jd5" ></th>
                <th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
            </tr>
        </thead>
    </table>
</div>

我想隐藏这个

<th data-column-id="qualification" data-class="hidden"></th>
                <th data-column-id="experience" data-class="hidden"></th>
                <th data-column-id="criteria1" data-class="hidden"></th>
                <th data-column-id="criteria2" data-class='hidden'></th>
                <th data-column-id="criteria3" data-class='hidden'></th>
                <th data-column-id="jd1" ></th>
                <th data-column-id="jd2" ></th>
                <th data-column-id="jd3" ></th>
                <th data-column-id="jd4" ></th>
                <th data-column-id="jd5" ></th>

但是..如果我隐藏了这些值..我无法访问它们

grid.find(".command-edit").on("click", function(e)
{
    //alert("You pressed edit on row: " + $(this).data("row-id"));
        var ele =$(this).parent();
        var g_id = $(this).parent().siblings(':first').html();
        var g_name = $(this).parent().siblings(':nth-of-type(7)').html();
                    console.log(g_id);
                console.log(g_name);

    //console.log(grid.data());//
    $('#edit_model').modal('show');
                if($(this).data("row-id") >0) {

                            // collect the data
                            // $('#edit_id').val(ele.siblings(':first').html()); // in case we're changing the key
                            $('#edit_position').val(ele.siblings(':nth-of-type(2)').html());
                            $('#edit_department').val(ele.siblings(':nth-of-type(3)').html());
                            $('#edit_vacancy').val(ele.siblings(':nth-of-type(4)').html());
                                                            $('#edit_qualification').val(ele.siblings(':nth-of-type(7)').html());
                                                            $('#edit_experience').val(ele.siblings(':nth-of-type(8)').html());
                                                            $('#edit_postingdate').val(ele.siblings(':nth-of-type(5)').html());
                                                            $('#edit_status').val(ele.siblings(':nth-of-type(6)').html());
                                                            // $('#edit_description').val(ele.siblings(':nth-of-type(9)').html());
                } else {
                 alert('Now row selected! First select row, then click edit button');
                }
})

我在Bootstrap-Table: How to hide a column without deleting it from the DOM? 尝试过解决方案 但它似乎根本没有隐藏该列

【问题讨论】:

    标签: php jquery ajax bootstrap-4


    【解决方案1】:

    如果您使用的是 bootstrap 4+,只需将 .d-none 类添加到您的列中,

    这将在它们上设置display: none

    如果您使用的是 bootstrap 3+,它应该是 .hidden-* 其中 *

    • xs
    • sm
    • md
    • lg

    适用于不同的屏幕尺寸。 也许.hidden 在没有尺寸选择器的情况下也能正常工作...

    【讨论】:

    • .hidden 不能解决我的问题..它仍然出现在我的桌子上
    • 您使用哪个引导程序版本?要使用隐藏,您可能需要在引导程序 3+ 上使用 hidden-xs hidden-sm hidden-md hidden-lg
    • 我使用引导程序 3.3.1。我使用 hidden-lg 但它仍然出现在我的桌子上
    • 好的,你能更新你的代码并显示你在哪里使用hidden-lg hidden-md.....
    • 表是自动生成的?如果是这样,您能否查看开发工具,您可能会看到 th 甚至没有显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2019-09-21
    • 1970-01-01
    相关资源
    最近更新 更多