如何在模态内提交时隐藏表格列 [英] How to hide table column on submit inside a modal

查看:79
本文介绍了如何在模态内提交时隐藏表格列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户个人资料页面上,我有一个表格,标题不在顶部,而是在左侧,描述在右侧.

On a user profile page I have a table where the headings are not on the top but on the left side, and descriptions are on the right.

当用户单击编辑配置文件"时,将打开一个模式.

When user clicks 'edit profile' a modal opens up.

在模式中,我想隐藏表列,或者在这种情况下,我想通过选择复选框然后单击保存更改"按钮来保存行.单击保存更改"后,他们的选择也应保存并在其个人资料上更新.

In the modal I want to hide table columns or I guess in this case rows by selecting the checkboxes and then hitting the 'save changes' button. When 'save changes' is clicked their choices should also be saved and updated on their profile.

我还希望在注册后首次访问其个人资料页面时已选中其中一些复选框.然后他们应该可以在那里进行更改.

I also want a few of the checkboxes to already be checked when they visit their profile page for the first time after registering. And then they should be able to change it there after.

我的代码无法正常工作,我尝试了所有我可以在隐藏列中找到的内容...我已经找了几天了.任何帮助深表感谢!

My code is not working and I tried everything I could find on hiding columns... I have been looking for days. Any help is much appreciated!

TABLE
<div class="row">
<table class="table table-responsive-sm" id="profileTable" id="table-pagination" cellspacing="0" style="width:100%" >
              <tbody>
                  <?php



          $sql = "SELECT `dancing_since`, `dancer_dob`, `school`, `school_code`,`teacher_name`, `class_location`, `date_enrolled`, `date_firstdance`, `first_dance_name`, `current_lvl` FROM `dancers` WHERE name = '$name' AND dancer_name = '$dancerName'";
          $res = mysqli_query($con,$sql); 

          //if($res==FALSE){
          //die('there was an error running query [' . $con->error . ']');
          //  }

          while($row=mysqli_fetch_array($res)){
              echo '
              <tr>
              <th class="tcol1">Dancing Since:</th>
              <td class="tcol1">'.$row["dancing_since"].'</td>
              </tr>

              <tr>
              <th class="tcol2">D.O.B:</th>
              <td class="tcol2">'.$row["dancer_dob"].'</td>
              </tr>


              <tr>
              <th class="tcol3">School:</th>
              <td class="tcol3">'.$row["school"].'</td>
              </tr>

              <tr>
              <th class="tcol4">School Code:</th>
              <td class="tcol4">'.$row["school_code"].'</td>
              </tr>

              <tr>
              <th class="tcol5">Teachers Name:</th>
              <td class="tcol5">'.$row["teacher_name"].'</td>
              </tr>

              <tr>
              <th class="tcol6">Class Location:</th>
              <td class="tcol6">'.$row["class_location"].'</td>
              </tr>

              <tr>
              <th class="tcol7">Date Enrolled:</th>
              <td class="tcol7">'.$row["date_enrolled"].'</td>
              </tr>

              <tr>
              <th class="tcol8">First Feis</th>
              <td class="tcol8">'.$row["first_dance_name"].'</td>
              </tr>

              <tr>
              <th class="tcol9">Date of First Feis:</th>
              <td class="tcol9">'.$row["date_firstdance"].'</td>
              </tr> 

              <tr>
              <th class="tcol10">Current Level:</th>
              <td class="tcol10">'.$row["current_lvl"].'</td>
              </tr> 
              ';  
    }

    ?>
</tbody>

MODAL

<!--POPUP MODAL FORM-->
                        <div class="formModal">
                            <div class="formModal text-right">
                                <button type="button" class="btn btn-outline-primary editprofile-btn" data-toggle="modal" data-target=".bd-editprofile-modal-lg">Edit Profile</button>
                            </div>


                            <!-- Modal -->

                            <div class="modal fade bd-editprofile-modal-lg" id="editProfile" tabindex="-1" role="dialog" aria-labelledby="editProfile" aria-hidden="true">
                                <div class="modal-dialog modal-dialog-centered modal-success modal-lg" role="document">
                                    <div class="modal-content">
                                        <form id="updateForm" method="post" class="form-horizontal" name="tcol" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" role="form" data-toggle="validator">
                                            <div class="controls">

                                                <!--Modal cascading tabs-->
                                                <div class="modal-c-tabs">

                                                    <!-- Nav tabs -->
                                                    <ul class="nav nav-tabs tabs-2 light-blue darken-3" role="tablist">
                                                        <li class="nav-item">
                                                            <a class="nav-link active" data-toggle="tab" href="#panel7" role="tab">Edit Profile Information</a>
                                                        </li>
                                                        <li class="nav-item">
                                                            <a class="nav-link" data-toggle="tab" href="#panel8" role="tab">Change visiblity</a>
                                                        </li>
                                                    </ul>

                                                    <!-- Tab panels -->
                                                    <div class="tab-content">

                                                        <!--Panel 7-->
                                                        //some code for edit profile form



                                                        <!-- PANEL 8 -->

                                                        <div class="tab-pane fade" id="panel8" role="tabpanel">
                                                            <div class="modal-body">
                                                                <div class="container-fluid">
                                                                    <div class="panel-8-heading text-center">
                                                                        <b>Select up to 10 abilities you would like to appear on your profile.</b>
                                                                    </div>
                                                                    <br>

                                                                    <div class="row">
                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col1" class="hidecol" id="col_1" data-column="0"/> Dancing Since
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col2" class="hidecol" id="col_2" checked="checked" data-column="1" /> D.O.B
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col3" class="hidecol" id="col_3" data-column="2"/> School
                                                                        </div>      
                                                                    </div>

                                                                    <div class="row">
                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col4" class="hidecol" id="col_4" checked="checked" data-column="3"/>  School Code
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col5" class="hidecol" id="col_5" checked="checked" data-column="4"/>  Teacher's Name
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" name="col6" class="hidecol" id="col_6" checked="checked" data-column="5"/> Class Location
                                                                        </div>
                                                                    </div>

                                                                    <div class="row">
                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" class="hidecol" name="col7" id="col_7" checked="checked" data-column="6"/> Date Enrolled
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" class="hidecol" name="col8" id="col_8" data-column="7" /> First competition
                                                                        </div>

                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" class="hidecol" name="col9" id="col_9" checked="checked" data-column="8"/> Date of First dance
                                                                        </div>
                                                                    </div>

                                                                    <div class="row">
                                                                        <div class="col-sm-4">
                                                                            <input type="checkbox" class="hidecol" name="col10" id="col_10" data-column="9"  /> Current Level
                                                                        </div>
                                                                        <div class="col-sm-4">
                                                                        </div>
                                                                        <div class="col-sm-4">
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <!-- PANEL 8 END -->
                                                    </div>
                                                </div>

                                                <!-- MODAL FOOTER -->
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                    <button type="submit" class="btn btn-primary" name="save" id="save">Save changes</button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>

JQUERY

$(document).ready(function() {


//modal checkbox


$('#profileTable tr td:nth-child(3)').hide();
});

编辑

下面是用户表和带有复选框的模态的图像.我希望能够隐藏整行.因此,如果用户取消选择位置,则在他们的个人资料上,他们将不再看到位置:新泽西州"

Below are images of the user table and the modal with checkboxes. I want to be able to hide the entire row. so if user deselect location then on their profile they would no longer see "location: NJ"

配置文件表

MODAL

推荐答案

我不知道这仅仅是代码的提取还是错误,因为我找不到模态中定义的任何<table>.从您的jquery代码中,您需要一个ID为profileTable的元素.

I don’t know if this is only an extract of the code or a mistake, because I can’t find any <table> defined in the modal. And from your jquery code you need an element with id profileTable.

我建议您说明您尝试过的内容以及不起作用的内容.此外,您可以较小程度地划分问题并确定根本原因.例如.尝试使用模态之外的隐藏/显示机制,或分解jquery代码(如果$('#profileTable tr td:nth-child(3)')不返回任何内容,则.hide()将无效)

I suggest you to state what have you tried and what is not working. Also you can divide the problem in a smaller scale and to identify the root cause. E.g. try the hide/show mechanism outside the modal, or break down the jquery code (if $('#profileTable tr td:nth-child(3)') return nothing then .hide() would take no effect)

更新1

我认为您正在尝试隐藏表格列(垂直列).首先,该表具有2个ID,分别为profileTabletable-pagination.删除任何一个,以便表​​具有一个唯一的ID.由于#是ID选择器,因此多个ID可能会使CSS混乱.其次,让我们将模式"放在一边.浏览器不了解模态,只知道有很多嵌套的html元素具有不同的样式.不论是否使用模式,javascript都应以相同的方式工作.它可以帮助您分解完整的模型并更轻松地找到根本原因.

I think you are trying to hide the table column(the vertical one). First, the table has 2 ids, profileTable and table-pagination. Remove either one so the table has exactly one id. Since # is a id selector, multiple id may mess up the css. Second, let's put "modal" aside. Browser has no knowledge about modal, it just know there are bunch of nested html elements with different styling. With or without modal, javascript should work the same way. It helps you to break down your through model and find the root cause easier.

我根据您提供的代码片段进行了演示.底部的两个按钮显示了如何隐藏和显示列.

I made a demo base on the snippet you provided. Two buttons at the bottom shows how to hide and show column.

https://codepen.io/anon/pen/oMpRbq

更新2

了解要求并更新演示.隐藏/显示行而不是列.概念几乎相同,不同之处在于选择tr而不是td.我只勾选了2个复选框,因为它们都相同.

Understand the requirement and update the demo. Hide/show the row instead of column. The concept is almost the same, the different is to select tr instead of td. I only make 2 checkbox since they are all the same.

$('#filter-panel').on('change', 'input', function(e) {
  var rowIndex = $(e.currentTarget).val();

  $('#profileTable tr:nth-child(' + rowIndex + ')').toggle();

});

table {
  border: 1px solid black;
  border-collapse: collapse;
}

table td,
table th {
  border: 1px solid black;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
  <table class="table table-responsive-sm" id="profileTable" cellspacing="0" style="width:100%">
    <tbody>
      <tr>
        <th class="tcol1">Dancing Since:</th>
        <td class="tcol1">'.$row["dancing_since"].'</td>
      </tr>

      <tr>
        <th class="tcol2">D.O.B:</th>
        <td class="tcol2">'.$row["dancer_dob"].'</td>
      </tr>

      <tr>
        <th class="tcol3">School:</th>
        <td class="tcol3">'.$row["school"].'</td>
      </tr>

      <tr>
        <th class="tcol4">School Code:</th>
        <td class="tcol4">'.$row["school_code"].'</td>
      </tr>

      <tr>
        <th class="tcol5">Teachers Name:</th>
        <td class="tcol5">'.$row["teacher_name"].'</td>
      </tr>

      <tr>
        <th class="tcol6">Class Location:</th>
        <td class="tcol6">'.$row["class_location"].'</td>
      </tr>

      <tr>
        <th class="tcol7">Date Enrolled:</th>
        <td class="tcol7">'.$row["date_enrolled"].'</td>
      </tr>

      <tr>
        <th class="tcol8">First Feis</th>
        <td class="tcol8">'.$row["first_dance_name"].'</td>
      </tr>

      <tr>
        <th class="tcol9">Date of First Feis:</th>
        <td class="tcol9">'.$row["date_firstdance"].'</td>
      </tr>

      <tr>
        <th class="tcol10">Current Level:</th>
        <td class="tcol10">'.$row["current_lvl"].'</td>
      </tr>
    </tbody>
  </table>
  <br /><br />

  <div id="filter-panel">

    <input type="checkbox" name="vehicle" value="1" checked/> dancing since
    <input type="checkbox" name="vehicle" value="2" checked/> d.o.b

  </div>

这篇关于如何在模态内提交时隐藏表格列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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