0

I have a table where I am able to get data from database. Here I am using two different tables to match the record and accordingly get the values if both table data gets matched. The values in database are ", " separated which I am able to split using explode function. Now the problem is that every element in database starts with "," and it returns first row as blank. Now when I am using Datatable to show the data, sorting is not working here tried too many solutions from different blogs but nothing working for me. I guess because it returns first row as blank sorting is not working.

Here is my view:

 <table id="tablevar" class="table table-sm">
      <thead>
        <tr>
          <th>
            Top Correlators
          </th>
          <th>
            Positive/Negative Correlation
          </th>
        </tr>
      </thead>
      @foreach(explode(', ', $detail->Topcorrelators) as $row)

          <tr>
              <td>
                {{ $row }}
              </td>
              @foreach($Correlations_list as $corr)
                @if($corr->Variable == $row )
                  <td>
                     @if($corr->Corr > 0)
                    <div class="progress">
                        <div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#e9ecef;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div> 
                        <div class="progress-bar progress-bar-striped" role="progressbar" style="width: 100%;background-color:#CA0088 " aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
  
                        </div>
                        Positive Correlator( {{ $corr->Corr }} )
                    @else
                    <div class="progress">
                        <div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#EAB330;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div> 
                        <div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#e9ecef;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div> 
                        </div>
                        Negative Correlator( {{ $corr->Corr }} )
                    @endif
                  </td> 

                  @endif
              @endforeach
          </tr>
      @endforeach
    </table>   

and this is my controller code:

 $Correlations_list=Correlation::all();
            return view('admin.members.Detailspage',compact('detail','Correlations_list'));

and this is my script:

$('#tablevar').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });

Any help ?

3
  • Why don't you just check for empty value and skip the row for that one? Commented Jul 12, 2021 at 10:59
  • @Frnak Can you tell me how I can do that in above code...? Commented Jul 12, 2021 at 11:24
  • @Frnak as I am new to laravel I am not sure how I can do that in blade? Commented Jul 12, 2021 at 11:26

1 Answer 1

1

You can check for empty value in that case

@foreach(explode(', ', $detail->Topcorrelators) as $row)
  @if(is_empty($row))
   @continue;
  @endif
  // ... rest of your code
@endforeach;

That should skip that empty row and fix your issue. You will find more info here: https://laravel.com/docs/5.4/blade#loops

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.