doupu9251 2016-10-17 08:22
浏览 32

Jquery在laravel动态表中隐藏和显示表行

I've been trying to get showing and hiding certain table rows to work in a dynamically generated table. The table itself gets its data from a laravel collection.
The idea behind the table is that we want to have users to show labelgroups, these groups can have zero, one, or more labels with that group number. I display the labels under their appropriate group.

The code is as follows:

<table id="labeltable" class="table table-bordered">
  @foreach($labelgroups as $labelgroup)
    @foreach($labelgroup->all() as $groep)
      <!-- Als de laatst ingevulde groep door de foreach loop verschillend is van de huidige groep, vul die dan in.
           Anders vul je deze en de rest van de headers niet in en wacht je tot er een nieuwe header is. -->
      @if($lastgroup !== $groep->groep)
        <thead>
          <tr>
            <td></td><!-- Empty line -->
          </tr>
          <tr style="background-color: #5cb85c">
            <th>{{ $groep->groep }}</th>
            <!-- Laatst ingevulde groep bepalen -->
            {{ $lastgroup = $groep->groep }}
            @if($event->present()->nl)
              <th>{{Initialise::lang('lbl.algemeen.taal_1')}}</th>
            @endif
            @if($event->present()->fr)
              <th>{{Initialise::lang('lbl.algemeen.taal_2')}}</th>
            @endif
            @if($event->present()->en)
              <th>{{Initialise::lang('lbl.algemeen.taal_3')}}</th>
            @endif
            @if($event->present()->de)
              <th>{{Initialise::lang('lbl.algemeen.taal_4')}}</th>
            @endif
          </tr>
        </thead>
      @endif
    @endforeach

    @foreach($labelgroup->all() as $label)
      <tbody>
        <tr class="{{ $groep->groep }}">
          <td>{{ $label->label }}</td>
          @if($event->present()->nl)
            <td>{!!  Form::textarea('taal_1',$label->taal_1, array('id' => $label->id.'_1','rows' => 2, 'data-taal' => 'taal_1', 'data-url' => LinkHelper::route('label.update',$label->id),'class' => 'form-control', 'onchange' => 'initialise.update("'.LinkHelper::route('label.update',$label->id).'","taal_1",this.value);')) !!}</td>
          @endif
          @if($event->present()->fr)
            <td>{!!  Form::textarea('taal_2',$label->taal_2, array('id' => $label->id.'_2','rows' => 2, 'data-taal' => 'taal_2', 'data-url' => LinkHelper::route('label.update',$label->id),'class' => 'form-control', 'onchange' => 'initialise.update("'.LinkHelper::route('label.update',$label->id).'","taal_2",this.value);')) !!}</td>
          @endif
          @if($event->present()->en)
            <td>{!!  Form::textarea('taal_3',$label->taal_3, array('id' => $label->id.'_3','rows' => 2, 'data-taal' => 'taal_3','data-url' => LinkHelper::route('label.update',$label->id),'class' => 'form-control', 'onchange' => 'initialise.update("'.LinkHelper::route('label.update',$label->id).'","taal_3",this.value);')) !!}</td>
          @endif
          @if($event->present()->de)
            <td>{!!  Form::textarea('taal_4',$label->taal_4, array('id' => $label->id.'_4','rows' => 2, 'data-taal' => 'taal_4','data-url' => LinkHelper::route('label.update',$label->id),'class' => 'form-control', 'onchange' => 'initialise.update("'.LinkHelper::route('label.update',$label->id).'","taal_4",this.value);')) !!}</td>
          @endif
        </tr>
      </tbody>
    @endforeach
  @endforeach
</table>

The table code generates the following table; the image is a part of the table:

Table example

Because the columns and rows are dynamically inserted I have no idea how to do a click event in which I can say that when I click on the header <th> element, I can hide the underlaying <td> elements (which represent labels that belong to the <th> group). Every <th> can have a different amount of rows corresponding with that 'group'.

Could somebody give me some indicators as to how I'm supposed to do this?

  • 写回答

1条回答 默认 最新

  • duanmibei1929 2016-10-17 10:59
    关注
    $('.class').on('click',function(){
        $(this).toggleClass('hiddenRow');
    })
    

    This will apply a click event on any elements with the class .class and when you click on it, it will toggle the class hiddenRow

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了