简体   繁体   中英

Trying to remove ROW from table but removes all my rows

I am trying to remove a row based on my laravel IF condition. So if my field is not empty, then I want it to delete that row. However, when the script runs it keeps deleting all the rows from my page and not just those that are NOT empty. Could somebody potentially from my code, identify where my issue lays? I've haven't included a thorough background on my problem because I believe it's simply an issue with my forloop or placement of the code? However reason I've put it in my foreach loop is so that I can access the "t->section" attribute.

I've tried adding a data attribute so that it targets only the specific column and not all of them. Also I want this to happen as soon as the user visits the page so therefore no buttons or 'on' clicks were required.

@foreach($displayTickets as $t)
                        <tr class="hide" data-id="{{$t->id}}">
                            <td><i class="fa fa-ticket" style="font-size: 16px" aria-hidden="true"></i><a
                                        href="/ticket/{{ $t->slug }}"
                                        class="subject-link">{{ $t->title }}</a></td>
                            <td>{{ $t->author }} {{$t->id}}</td>
                            <td>{{ $t->subject_area }}</td>
                            <td>{{ $t->created_at }}</td>
                            <td>{{ $t->reply_count }}</td>
                            <td>
                                @if($t->status == 'Open')
                                    <span class="status-green">{{ $t->status }}</span>
                                @elseif($t->status == 'Closed')
                                    <span class="status-red">{{ $t->status }}</span>
                                @endif
                            </td>
                            <script type="text/javascript">
                            @if(!empty($t->section))
                                    jQuery(document).ready(function () {
                                        $('.hide').filter(function(){
                                           return $(this).data('id')
                                        }).remove();
                                    });
                                @endif    
                            </script>
                        @endforeach
                        </tr>
                    </tbody>
                </table>

if you don't need those rows and they are not use on the rest of the page you can filter tickets one step earlier in your controller with where clause:

$displayTickets = Ticket::latest()->where('section',null)->get()

if you need them and just need to hide them in datatable:

<table>
                <tbody>
                @foreach($displayTickets as $t)
                    @if(empty($t->section))
                    <tr class="hide" data-id="{{$t->id}}">
                        <td><i class="fa fa-ticket" style="font-size: 16px" aria-hidden="true"></i><a href="/ticket/{{ $t->slug }}" class="subject-link">{{ $t->title }}</a>
                        </td>
                        <td>{{ $t->author }} {{$t->id}}</td>
                        <td>{{ $t->subject_area }}</td>
                        <td>{{ $t->created_at }}</td>
                        <td>{{ $t->reply_count }}</td>
                        <td>
                        @if($t->status == 'Open')
                            <span class="status-green">{{ $t->status }}</span>
                        @elseif($t->status == 'Closed')
                            <span class="status-red">{{ $t->status }}</span>
                        @endif
                        </td>
                     </tr>
                     @endif
                @endforeach
                </tbody>
            </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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