2016-05-15 10 views
1

私はlaravel 5.2フレームワークを使用しています。私はデータテーブルをうまく実装しました。問題は私のアプリケーション設計では、データテーブルセル内にテーブルを実装する必要があることです。私はこれをどうやってやっていくのか分かりません。私は何日もグーグルグーグルを過ごしたので、この助けに感謝します。データテーブル内のセル内のテーブルlaravel 5.2

答えて

1

その本当に直接可能私の見解上のHTML

の私のテーブルの

<style type="text/css"> 

    h3 { 
     color: steelblue; 
    } 
    .subtabletable { 
     display: table; 
     width: 100%; 
     } 
    .subtable .row { 
    display: table-row; 
     } 
    .subtable .header { 
    font-weight: bold; 
    } 
    .subtable .cell { 
    display: table-cell; 
    padding: 5px; 
    } 

    </style> 

定義を定義し、私の内側のテーブルのための

styesを次のようにあなた自身のテーブルとスタイルは、CSSでそれを定義しない限り、

<table id="example" class="display responsive nowrap" cellspacing="0" width="100%"> 

私のjavascript

  $(document).ready(function() { 




var request = $.ajax({ 
           url: "sort_respones", 
           type: "GET", 
           dataType: "html" 
           }); 



        request.done(function(msg){ 
         dynamicdatatable(msg); 
        }); 


    }); 

    function dynamicdatatable(mydata){ 
var myData=JSON.parse(mydata) ; 
console.log(myData); 
var myColumns = [ 
    { 
     title : "Employee", 
     data : "question" 
    }, 
    { 
     title : "Type", 
     data : "response_type" 
    }, 
    { 
     title : "Responses", 
     data : null, 
     render : function (data, type, row, meta) { 
      var subtableHtml = "<div class='subtable'>"; 
      subtableHtml += "<div class='row header'><span class='cell'>Response</span><span class='cell'>Occurances</span></div>"; 
      for (var i = 0; i < data.projects.length; i++) { 
       subtableHtml += "<div class='row'>"; 
       subtableHtml += "<span class='cell'>" + data.projects[i].project + "</span>"; 
       subtableHtml += "<span class='cell'>" + data.projects[i].role + "</span>"; 
       subtableHtml += "</div>"; 
      }; 
      subtableHtml += "</div>"; 
      return subtableHtml; 
     } 
    } 
]; 

$('#example').dataTable({ 
    searching: false, 
    paging: false, 
    data : myData, 
    columns : myColumns, 
    dom: 'Bfrtip', 
    buttons: [ 
     'copyHtml5', 
     'excelHtml5', 
     'csvHtml5', 
     'pdfHtml5' 
    ] 
    }); 


} 
もちろん

私のコントローラ機能

function sort_respones(Request $request){ 

    $results = DB::select(DB::raw("SELECT 
       questions.id, 
       questions.question, 
       questions.client_id, 
       surveys_session_answer_transactions.created_at, 
       surveys_session_answer_transactions.answer_text, 
       surveys_session_answer_transactions.answer_id, 
       surveys_session_answer_transactions.question_text, 
       questions.response_type_id, 
       Count(surveys_session_answer_transactions.answer_id) AS Occurances, 
       checkresponses.response, 
       radioresponses.response, 
       rating_bar_responses.maximum_value, 
       response_types.response_type 
       FROM 
       questions 
       INNER JOIN surveys_session_answer_transactions ON surveys_session_answer_transactions.question_id = questions.id 
       LEFT OUTER JOIN checkresponses ON checkresponses.question_id = surveys_session_answer_transactions.question_id AND checkresponses.id = surveys_session_answer_transactions.answer_id 
       LEFT OUTER JOIN rating_bar_responses ON rating_bar_responses.question_id = surveys_session_answer_transactions.question_id 
       LEFT OUTER JOIN radioresponses ON radioresponses.question_id = surveys_session_answer_transactions.question_id AND radioresponses.id = surveys_session_answer_transactions.answer_id 
       INNER JOIN response_types ON surveys_session_answer_transactions.response_type_id = response_types.type_id 
       where questions.client_id=:somevariable 
       GROUP BY 
       surveys_session_answer_transactions.question_id, 
       surveys_session_answer_transactions.answer_id"), array(
      'somevariable' => "2", 
     )); 

    //echo '<pre>'.print_r($results,1) .'</pre>'; 

      // echo '<pre>'; 
    //  var_dump($results); 
    //  echo '</pre>'; 
    $new_question=0; 
    $dataUsage=[]; 
    $final_array=[]; 
    $responses=[]; 
    $old_response="";$old_response_type=""; 
    foreach ($results as $key) { 
     # code... 
     if ($new_question!=$key->id) { 
      # code... 
      if (isset($dataUsage[0])) { 
       # code... 

       array_push($final_array, array('question' =>$old_response,'response_type'=>$old_response_type,'projects' => ($responses))); 
       $responses=[]; 

       //array_push($final_array, $dataUsage); 
       $dataUsage=[]; 
       $responses_string="<table>"; 
      } 
     array_push($dataUsage, array('question' => $key->question,'response_type'=>$key->response_type)); 
      $old_response=$key->question; 
      $old_response_type=$key->response_type; 
     // $responses_string='<TR><TD>'.$key->answer_text.'</TD><TD>: '.$key->Occurances.'<br></TD></TR>'; 
      array_push($responses,array('project' => $key->answer_text, 'role' => $key->Occurances)); 
       }else{ 
     // $responses_string=$responses_string.'<TR><TD>'.$key->answer_text.'</TD><TD> :'.$key->Occurances.'<br></TD></TR>'; 
     array_push($responses,array('project' => $key->answer_text, 'role' => $key->Occurances));   

     } 
     $new_question=$key->id; 
    } 
     array_push($final_array, array('question' =>$old_response,'response_type'=>$old_response_type,'projects' => ($responses))); 


     // echo '<pre>'; 
     // var_dump($final_array); 
     // echo '</pre>'; 
    // echo json_encode(array('data' =>$final_array)); 
    // $myData = array(array('employee' =>'Bob Smith', 'projects'=>   array(array('project'=>'Alpha', 'role'=>'leader'), array('project'=>'Alpha1', 'role'=>'leader1'),array('project'=>'Alpha', 'role'=>'leader')))); 
    echo json_encode($final_array); 
} 

必要なルートにそれが働いた

+0

感謝を忘れないでください。しかし、あなたのクエリ?? –

+0

それを雄弁に変えるにはあまりにも怠惰です。うれしいことに、 –

+0

と認識しているかもしれません。JavaScript/jqueryの画像、向き、圧縮、投稿で助けてくれるかもしれません。 –

関連する問題