2017-07-12 30 views
1

JSONから返されたDataTableは、行をクリックして詳細を展開したJSON戻り値を持ち、JSONからリストをロードします。これを行うには、exampleに従ってください。Jqueryデータテーブルの現在の詳細

私はそれがデータテーブルの行のシーケンスであるかのように、それを隠すことなく、詳細をロードするように拡張するためのオプションと崩壊を持つことができませんどのように知っていただきたいと思い

、詳しくは常に表示されている必要があり

Column1| Column2| Column3| 
Value1 Value2 Value3 
    Detail1| Detail2| Detail3| 
    ValueD1 ValueD2 ValueD3 

UPDATE - JSONここ

$scope.list = [ 
      { 
       id:1, 
       name: "Ze", 
       listDetail: [ 
        { 
         id:1, 
         description: "lt" 
        }, 
        { 
         id:2, 
         description: "lt 3" 
        }, 
       ] 
      }, 
      { 
       id:2, 
       name: "Ze 2", 
       listDetail: [ 
        { 
         id:3, 
         description: "lt 1" 
        }, 
        { 
         id:4, 
         description: "lt 4" 
        }, 
       ] 
      } 
     ]; 
+0

通常のデータテーブルを作成するとしますが、詳細行の場合は、td: 'colspan = nbOfColumn'に属性を追加し、詳細をtdに入れます。 –

+0

私はこの角度ジェスの世界を研究し始めています.JQueryの他にも、私は 'colspan = nbOfColumn'を検索しようとしました。しかし私は私を助けることができる具体的な何かを見つけませんでした、あなたは例がありますか? – user8223022

+0

JSONの例を教えてもらえますか?サーバー側で働いていますか?あなたはJSONを生成していますか? –

答えて

0

、それが動作するはずです:ここでは

を、JSで動作するはずのソリューションです上のように:

  • JSON

{ "draw": 2, "recordsTotal": 3, "recordsFiltered": 3, "data": [{ "type": "normal", "description": "Zenaida", "name": "Frank", "age": "Software Engineer", "location": "New York" }, { "type": "detail", "detail": "first detail" }, { "type": "detail", "detail": "second detail" }, { "type": "detail", "detail": "third detail" }, { "type": "normal", "description": "zerrz", "name": "paul", "age": "Software breaker", "location": "Lodon" }, { "type": "detail", "detail": "third detail" }, { "type": "normal", "description": "Zenaida", "name": "Frank", "age": "Software Engineer", "location": "New York" }, { "type": "detail", "detail": "second detail" }, { "type": "detail", "detail": "third detail" }] }

  • JS

$('#example').dataTable({ "processing": true, "serverSide": true, "ajax": "YourAjaxSource", "columns": [ //You have to manually bind your column since the first value is not to be displayed { "data": "details" }, { "data": "description" }, { "data": "name" }, { "data": "age" }, { "data": "location" } ], "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { switch (aData[0]) { //first value indicates if its a detail row or a normal row case 'normal': // if its a normal row, just display the cells without the first detail one $(nRow).find('td')[0].style.display = 'none'; break; case 'detail': //else display none of the cells except the detail one with take up 5 cells $(nRow).find('td')[1].style.display = 'none'; $(nRow).find('td')[2].style.display = 'none'; $(nRow).find('td')[3].style.display = 'none'; $(nRow).find('td')[4].style.display = 'none'; $(nRow).find('td')[0].colSpan = '5'; //Your number of column break; } } });

それが動作する方法は、各行がtechnicly詳細を持っています+正常細胞。

最後に詳細行のための私ができるようにするためにセルの数の属性COLSPANを与えることが行ごとに行の種類を確認し、そして(他は空であるので)のみ必要なセルを表示描画それは行の幅をすべて取る。

私はそれをテストしていないのでgl & hf;)何か問題があるならば、コメントすることを躊躇しないでください。

必要に応じて調整してください。

+0

答えをありがとう、私はあなたの例に従って行う傾向があり、私は成功しませんでした。あなたの例からわかるように、JSONの戻り値はJSONの戻り値とは多少異なります。つまり、別のリストの中にリストがあります。つまり、メインのコンテンツに詳細コンテンツのリストが含まれています。あなたのJSONが私とは異なるフォーマットになっているので、あなたが私に例を挙げた方法で、私はそれを動作させる方法を理解できませんでした。 – user8223022

関連する問題