简体   繁体   English

当我在 laravel 8 项目上单击它时在表行上添加类

[英]Adding class on a table row when i click it on laravel 8 project

I am developing a web application using laravel 8 and Livewire.我正在使用 laravel 8 和 Livewire 开发一个 Web 应用程序。

In the views of my application I have tables in which I show partial data taken from the DB and clicked on the specific row of which you want to have the details then I recover all the information I need.在我的应用程序的视图中,我有一些表格,其中显示了从数据库中获取的部分数据,并单击了您想要获取详细信息的特定行,然后我恢复了我需要的所有信息。

To ensure that the user has visual feedback when they click on a table row of which they are reading the detail.确保用户在单击他们正在阅读详细信息的表格行时获得视觉反馈。

To obtain this result I have inserted on the rows of the table an onclick="toggleClass(this, 'table-info')" method that calls a script to achieve this purpose, which adds to the clicked row the class table-info为了获得这个结果,我在表的行上插入了一个onclick="toggleClass(this, 'table-info')"方法,该方法调用了一个脚本来实现这个目的,它将类table-info添加到被点击的行

The problem I get though is the following, when I click on the table row, the class is added to the row for a few seconds and then it is lost, and consequently I lose the highlight of the row.我得到的问题如下,当我点击表格行时,类被添加到行中几秒钟然后它丢失了,因此我丢失了该行的突出显示。

Do you have any suggestions or ideas?你有什么建议或想法吗? Thanks to all!谢谢大家!

Here my code:这是我的代码:

  • table-pratiche-content.blade.php ( livewire component ) table-pratiche-content.blade.php ( livewire 组件)
<tbody>
    @if (!empty($pratiche))
        <?php
        $carico = 0;
        $riscosso = 0;
        $sgravio = 0;
        $residuo = 0;

        $first = null;
        $last =null;
        $current = null;
        $next = null;
        $prev = null;
        ?>
        @foreach ($pratiche['data'] as $p)
            <tr wire:click="clickPartiteTrigger({{ $p['id_minuta'] }})" onclick="toggleClass(this, 'table-info')">
                <td>@if(isset($p['denominazioneSoggetto'])) {{ $p['denominazioneSoggetto'] }} @else - @endif</td>
                <td>@if(isset($p['codiceFiscale'])) {{ $p['codiceFiscale'] }} @else - @endif</td>
                <td>@if(isset($p['indirizzoPOSTA'])) {{ $p['indirizzoPOSTA'] }} @else - @endif</td>
                <td>@if(isset($p['descrizione_sintetica']) && $p['descrizione_sintetica'] != '' ) {{ $p['descrizione_sintetica'] }} @else - @endif</td>
                <td>@if(isset($p['carico'])) {{ $p['carico'] }} &euro; @else - @endif</td>
                <td>@if(isset($p['riscosso'])) {{ $p['riscosso'] }} &euro; @else - @endif</td>
                <td>@if(isset($p['sgravio'])) {{ $p['sgravio'] }} &euro; @else - @endif</td>
                <td>@if(isset($p['residuo'])) {{ $p['residuo'] }} &euro; @else - @endif</td>
                <td>@if(isset($p['collaboratore'])) {{ $p['collaboratore'] }} @else - @endif</td>
                <td>@if(isset($p['data_assegnazione'])) {{ $p['data_assegnazione'] }} @else - @endif</td>
                @if($p['residuo']>0)
                    <td><span class="badge light badge-warning">Non riscosso</span></td>
                @else
                    <td><span class="badge light badge-success">Riscosso</span></td>
                @endif
                <?php
                    $carico = $carico + $p['carico'];
                    $riscosso = $riscosso + $p['riscosso'];
                    $sgravio = $sgravio + $p['sgravio'];
                    $residuo = $residuo + $p['residuo'];
                ?>
            </tr>
        @endforeach
            <?php
                    $first = $pratiche['first_page_url'];
                    $last = $pratiche['last_page_url'];
                    $current = $pratiche['current_page'];
                    $next = $pratiche['next_page_url'];
                    $prev = $pratiche['prev_page_url'];
            ?>
    @endif
</tbody>
<livewire:tbl-pratiche-footer-filter :carico="$carico" :riscosso="$riscosso" :sgravio="$sgravio" :residuo="$residuo" 
                :first="$first" :last="$last" :current="$current" :next="$next" :prev="$prev" :pratiche="$pratiche" />

 @push('custom_scripts')
 <script type="text/javascript">
        function toggleClass(el, className) {
            if (el.className.indexOf(className) >= 0) {
                el.className = el.className.replace(className,"");
        }
        else {
                el.className  += className;
            }
        }
</script>
 @endpush
  • table-pratiche.blade.php表pratiche.blade.php
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title">Pratiche</h4>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                  <table class="table table-hover table-responsive-md" id="tblpratiche">
                    <thead>
                      <tr>
                        <th>Soggetto</th>
                        <th>Codice Fiscale</th>
                        <th>Indirizzo</th>
                        <th>Tipo di imposta</th>
                        <th>Carico</th>
                        <th>Riscosso</th>
                        <th>Sgravio</th>
                        <th>Residuo</th>
                        <th>Assegnatario</th>
                        <th>Data assegn.</th>
                        <th>Dettagli</th>
                      </tr>
                    </thead>
                    <livewire:table-pratiche-content />

Declare a public property in the Livewire Component (The PHP Class)在 Livewire 组件(PHP 类)中声明一个公共属性

public $markedRows = [];

create a function创建一个函数

public function markRow($id) {
    $this->markedRows[] = $id;
}

when you iterate in your blade, check that the current id in the iteration is in_array of $markedRows and do whatever you need to do.当您在刀片中进行迭代时,请检查迭代中的当前 id 是否为$markedRows in_array并执行您需要执行的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM