function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
吉田 丈治吉田 丈治 

VisualforceページにMatrixを表示するには

User-added image

WorkbenchのSOQL Queryでこんな感じの表が出力出来そうなことは分かっているのですが、Visualforceページにうまくのせられず困っております。

User-added image
SELECT sum(point_2016_8__c),CreatedById,PMT__c 
FROM projectmembers__c 
WHERE member__c = 'a1i10000004Mnfj'  
group by CreatedById,PMT__c

Class
public void countPMT(){
        repoOwnerId = [Select Id,ownerId from MyReport__c where Id= :repo.Id].ownerId;
        List<AggregateResult> allPMTByOthers = [SELECT sum(point_2016_8__c) pointsum ,CreatedById,PMT__c 
                               FROM projectmembers__c 
                               WHERE member__c = :repoOwnerId 
                               group by CreatedById,PMT__c 
                                  ];
    }

VF
 <apex:pageBlockTable value="{!allPMTByOthers}" var="t">
                <apex:column value="{!t.CreatedById}"/>
                <apex:column value="{!t.PMT__c}"/>
                <apex:column value="{!t.pointsum}"/> 
            </apex:pageBlockTable>

良くわからないこと
・Matrix表示時に、Rowを指定する方法
  ・columnは上記のような感じで良さそうなのですが、rowの指定はどのようにすればよいのでしょうか
・sum(point_2016_8__c) pointsum としているのですが、VF側で{!t.pointsum}とするとエラーが出ます
エラー: Invalid field pointsum for SObject projectmembers__c

WorkbenchのQuery resultの様に表示をしたいのですが、そこでつまづきました。
お知恵をいただけると助かります。
Best Answer chosen by 吉田 丈治
Yosuke EnomotoYosuke Enomoto

ベストな回答かどうかはわかりませんが、私はSQOLのgroup by cubeと通常のHTMLのtableとapex:repeatを組み合わせて実装しています。
 
<table class="detailTable">
  <thead>
    <th style="width:200px">タイトル</th>
    <apex:repeat value="{!取得した結果}" var="si">
      <apex:outputlabel >
        <th style="width:50px;text-align:center;">{!ヘッダーとなる項目}</th>
      </apex:outputlabel>
    </apex:repeat>
    <th style="width:70px">小計</th>
  </thead>

  <tfoot>
    <tr class="odd">
        <th style="padding-left:10px;">
          <apex:outputLabel >サイズ小計</apex:outputLabel>
        </th>
      <apex:repeat value="{!size_info}" var="si">
        <th style="text-align:center">
          <apex:repeat value="{!results}" var="rst2">
   <--ここに集計結果を入れる-->
            <apex:outputlabel rendered="{!集計したい条件}">
              <apex:outputlabel >{!集計値}</apex:outputlabel>
            </apex:outputlabel>
          </apex:repeat>
        </th>
      </apex:repeat>
    </tr>
  </tfoot>
  <tbody>
      <--明細も上記の様に条件と明細を出力する様に修正-->
  </tbody>
</table>
SOQL
select  項目1,grouping(項目1),  項目2,grouping(項目2),  sum(集計値) quantity 
              from object 
              group by cube(項目1,項目2)
※groupingで取得した項目(0 or 1)で、どの項目を集計するか判定しています。

他により良い方法が有れば、私も知りたいですね。

 

All Answers

Yosuke EnomotoYosuke Enomoto

ベストな回答かどうかはわかりませんが、私はSQOLのgroup by cubeと通常のHTMLのtableとapex:repeatを組み合わせて実装しています。
 
<table class="detailTable">
  <thead>
    <th style="width:200px">タイトル</th>
    <apex:repeat value="{!取得した結果}" var="si">
      <apex:outputlabel >
        <th style="width:50px;text-align:center;">{!ヘッダーとなる項目}</th>
      </apex:outputlabel>
    </apex:repeat>
    <th style="width:70px">小計</th>
  </thead>

  <tfoot>
    <tr class="odd">
        <th style="padding-left:10px;">
          <apex:outputLabel >サイズ小計</apex:outputLabel>
        </th>
      <apex:repeat value="{!size_info}" var="si">
        <th style="text-align:center">
          <apex:repeat value="{!results}" var="rst2">
   <--ここに集計結果を入れる-->
            <apex:outputlabel rendered="{!集計したい条件}">
              <apex:outputlabel >{!集計値}</apex:outputlabel>
            </apex:outputlabel>
          </apex:repeat>
        </th>
      </apex:repeat>
    </tr>
  </tfoot>
  <tbody>
      <--明細も上記の様に条件と明細を出力する様に修正-->
  </tbody>
</table>
SOQL
select  項目1,grouping(項目1),  項目2,grouping(項目2),  sum(集計値) quantity 
              from object 
              group by cube(項目1,項目2)
※groupingで取得した項目(0 or 1)で、どの項目を集計するか判定しています。

他により良い方法が有れば、私も知りたいですね。

 
This was selected as the best answer
吉田 丈治吉田 丈治
ありがとうございます!
Workbenchで出来るのであれば、そのまま実装できそうなのにそうでもないんですね。
良い方法絶賛募集中です。