2014-07-09 3 views
0

저는 Laravel 4를 사용하여 정말 새롭습니다. 여기서 아주 간단한 문제가 있습니다.컬러 버튼이있는 Laravel 쿼리

여기에이 쿼리를 호출합니다.

$users = DB::table('alumnos')->select(array('id', 'Nombre', 'Apellidos','Seccion','Grado','Preceptor','P1','P2','P3','P4','P5','P6','P7','P8')); 
return Datatables::of($users) 

그리고이 같은 테이블을 채우는 오전 :

+--------+-----------+------------+ 
    | Nombre | Apellidos | P1  | 
    +--------+-----------+------------+ 
    |Nombre 1|Apellido1 | 0  | 
    |Nombre 1|Apellido1 | 1  |  
    |Nombre 1|Apellido1 | 0  |  
    |Nombre 1|Apellido1 | 1  |  
    |Nombre 1|Apellido1 | 1  |  
    |Nombre 1|Apellido1 | 1  | 
    +--------+-----------+------------+ 

의 표는 자바 스크립트 코드를 사용하여 채워집니다

var oTable; 
    $(document).ready(function() { 
      oTable = $('#registros').dataTable({ 
      "sDom": "<l><f><r>t<i><p>", 
      "sPaginationType": "bootstrap", 
      "oLanguage": { 
       "sSearch": "Search:", 
       "sLengthMenu": "_MENU_ records per page" 
      }, 
      "bProcessing": true, 
      "bServerSide": true, 
      "sAjaxSource": "{{ URL::to('registrar/datadirectivos') }}" 
     }); 

     $("#users_filter input").addClass("form-control inline-control input-sm"); 
     $("#users_length select").addClass("form-control inline-control"); 
    }); 

내가 Preceptoria라는 이름의 마지막 열을 변경되고 싶지 숫자 대신에 열보기 단추가 dinamically 1 개의 단추가 초록색으로 표시되고 0이면 단추는 빨간색으로 표시됩니다.

+0

가 왜 단순히 적절하게 색 버튼을 표시 블레이드 템플릿에 @if 있습니다

나는 자바 스크립트 코드를 변경? –

+0

어떻게 할 수 있습니까? 몇 가지 예제 코드가 있습니까? –

답변

0

이미 해결되었습니다.

$(document).ready(function() { 
oTable = $('#registros').dataTable({ 
      "sDom": "<l><f><r>t<i><p>", 
      "sPaginationType": "bootstrap", 
      "oLanguage": { 
       "sSearch": "Search:", 
       "sLengthMenu": "_MENU_ records per page" 
      },"fnRowCallback": function(nRow, aData, iDisplayIndex,iDisplayIndexFull) { 
      $(nRow).children().each(function(index, td) { 
         if(index == 5 || index == 6 || index == 7 || index == 8 || index == 9 || index == 10 || index == 11 || index == 12) { 
          if ($(td).html() === "0") { 
           $(td).html("<button class='btn' style='background-color:#A8383B;'>P1</button>"); 
          } 
          if ($(td).html() === "1") { 
           $(td).html("<button class='btn' style='background-color:#3C8D2F;'>P1</button>"); 
          }           
         } 
      });      
    return nRow; 
    }, 
      "bProcessing": true, 
      "bServerSide": true, 
      "sAjaxSource": "{{ URL::to('registrar/datadirectivos') }}" 
     }); 
     $("#users_filter input").addClass("form-control inline-control input-sm"); 
     $("#users_length select").addClass("form-control inline-control"); 
    });