Skip to main content
added 3945 characters in body
Source Link
Guillaume
  • 115
  • 1
  • 13

Edit with code:

Controller with an inner class containing headers (=fields) and a list of records. Some queries are created from values contained in a custom object TodoBlock__c, then they are used to fill the list "records".

public with sharing class ToDoBlockController{ public TodoBlock todoBlock {get;set;} public void initComponent(){ // init todoblock } public class TodoBlock{ // input public String name {get;set;} public String query {get;set;} public List<String> headers {get;set;} public Integer queryLimit {get;set;} // calculation public List<SObject> records {get;set;} public Integer count {get;set;} public String objType {get;set;} // modification public String sortColumn {get{ return sortColumn==null ? headers[0] : sortColumn; } set;} public boolean isAscSort {get{ return isAscSort==null ? true : isAscSort; } set;} public TodoBlock(TodoBlock__c record, Integer queryLimit, String sortColumn, String isAscSortStr){ // attributes initialization } public void runQueries(){ // queries records } } 

}

Visualforce component containing the table.
I am having trouble displaying it correctly, anyway important part is under the 2 comments. Here i would like to format the value depending on its type. Value is record[header] result. Type can be anything.
I see 2 option :

  • I can get type from VF side => i create tags with conditions in rerender attribute

  • I need to store it somewhere in the controller => instead of String[] header I shoud use Map{String=>String} where key is header/field name and value is type

    <apex:pageBlockSection columns="1" rendered="{!errorMessage==null}"> <apex:pageBlockTable value="{!todoBlock.records}" var="rec" width="100%" rendered="{!todoBlock.Records.SIZE>0}"> <apex:repeat value="{!todoBlock.headers}" var="header"> <apex:column width="10%"> <apex:facet name="header">
    <apex:outputPanel >
    {!$ObjectType[todoBlock.objType].fields[header].label} <apex:image title="{!IF(AND(todoBlock.sortColumn = header,todoBlock.isAscSort),'Sorted Ascending', 'Sorted Descending')}" styleClass="{!IF(AND(todoBlock.sortColumn = header,todoBlock.isAscSort),'sortAsc', 'sortDesc')}" alt=""
    rendered="{!todoBlock.sortColumn = header}" value="/s.gif"/> </apex:outputPanel> </apex:facet>

     <!-- 1st col = link --> <apex:outputLink value="/{!rec.Id}" target="_blank" rendered="{!header == todoBlock.headers[0]}">{!rec[header]}</apex:outputLink> <!-- other cols = normal --> <apex:outputLabel rendered="{!header != todoBlock.headers[0]}">{!rec[header]}</apex:outputLabel> </apex:column> </apex:repeat> </apex:pageBlockTable> </apex:pageBlockSection> 

Edit with code:

Controller with an inner class containing headers (=fields) and a list of records. Some queries are created from values contained in a custom object TodoBlock__c, then they are used to fill the list "records".

public with sharing class ToDoBlockController{ public TodoBlock todoBlock {get;set;} public void initComponent(){ // init todoblock } public class TodoBlock{ // input public String name {get;set;} public String query {get;set;} public List<String> headers {get;set;} public Integer queryLimit {get;set;} // calculation public List<SObject> records {get;set;} public Integer count {get;set;} public String objType {get;set;} // modification public String sortColumn {get{ return sortColumn==null ? headers[0] : sortColumn; } set;} public boolean isAscSort {get{ return isAscSort==null ? true : isAscSort; } set;} public TodoBlock(TodoBlock__c record, Integer queryLimit, String sortColumn, String isAscSortStr){ // attributes initialization } public void runQueries(){ // queries records } } 

}

Visualforce component containing the table.
I am having trouble displaying it correctly, anyway important part is under the 2 comments. Here i would like to format the value depending on its type. Value is record[header] result. Type can be anything.
I see 2 option :

  • I can get type from VF side => i create tags with conditions in rerender attribute

  • I need to store it somewhere in the controller => instead of String[] header I shoud use Map{String=>String} where key is header/field name and value is type

    <apex:pageBlockSection columns="1" rendered="{!errorMessage==null}"> <apex:pageBlockTable value="{!todoBlock.records}" var="rec" width="100%" rendered="{!todoBlock.Records.SIZE>0}"> <apex:repeat value="{!todoBlock.headers}" var="header"> <apex:column width="10%"> <apex:facet name="header">
    <apex:outputPanel >
    {!$ObjectType[todoBlock.objType].fields[header].label} <apex:image title="{!IF(AND(todoBlock.sortColumn = header,todoBlock.isAscSort),'Sorted Ascending', 'Sorted Descending')}" styleClass="{!IF(AND(todoBlock.sortColumn = header,todoBlock.isAscSort),'sortAsc', 'sortDesc')}" alt=""
    rendered="{!todoBlock.sortColumn = header}" value="/s.gif"/> </apex:outputPanel> </apex:facet>

     <!-- 1st col = link --> <apex:outputLink value="/{!rec.Id}" target="_blank" rendered="{!header == todoBlock.headers[0]}">{!rec[header]}</apex:outputLink> <!-- other cols = normal --> <apex:outputLabel rendered="{!header != todoBlock.headers[0]}">{!rec[header]}</apex:outputLabel> </apex:column> </apex:repeat> </apex:pageBlockTable> </apex:pageBlockSection> 
deleted 44 characters in body; edited title
Source Link
battery.cord
  • 8.9k
  • 8
  • 33
  • 59

VF Visualforce dynamic sObject table of SObjects (cols = fields) - how to check type to apply format (dates ...)column value formatting

I want to allow my team to display some leads and tasks (and any knowknown object) with custom conditions and display all the data on only one screen. I made some custom objects "blocks" containing SOQL elements :

  • base query ; ex: select * from lead where createdDate = TODAY
  • headers ; ex: Name, CreatedDate, id

I have a controller that get all those blocks then get all the records in wrappers with a list of headers and a list of those sobjects.

Then I have a visualforce page that use repeat vf command :

  • repeat on all wrappers to create tables
  • repeat on all headers to create the table header then fill the rows & 1st column is a link to the record

This way my team can work on only one screen with data we want.

But I would like to be able to format the output value, depending on the type. Obviously for dates and datetimes.

Is there a way I can acheive this ?

I am just thinking about one thing : I could use a map of headers instead of a list, key = header, value = type. GetHeaders => return List(headers.keySet()) Sosomething like:

key = header, value = type. GetHeaders => return List<String>(headers.keySet()) 

So in my columns i could check the type to use some formated output values.

Any other idea ?

Thanks :)

VF dynamic table of SObjects (cols = fields) - how to check type to apply format (dates ...)

I want to allow my team to display some leads and tasks (and any know object) with custom conditions and display all the data on only one screen. I made some custom objects "blocks" containing SOQL elements :

  • base query ; ex: select * from lead where createdDate = TODAY
  • headers ; ex: Name, CreatedDate, id

I have a controller that get all those blocks then get all the records in wrappers with a list of headers and a list of those sobjects.

Then I have a visualforce page that use repeat vf command :

  • repeat on all wrappers to create tables
  • repeat on all headers to create the table header then fill the rows & 1st column is a link to the record

This way my team can work on only one screen with data we want.

But I would like to be able to format the output value, depending on the type. Obviously for dates and datetimes.

Is there a way I can acheive this ?

I am just thinking about one thing : I could use a map of headers instead of a list, key = header, value = type. GetHeaders => return List(headers.keySet()) So in my columns i could check the type to use some formated output values.

Any other idea ?

Thanks :)

Visualforce dynamic sObject table column value formatting

I want to allow my team to display some leads and tasks (and any known object) with custom conditions and display all the data on only one screen. I made some custom objects "blocks" containing SOQL elements :

  • base query ; ex: select * from lead where createdDate = TODAY
  • headers ; ex: Name, CreatedDate, id

I have a controller that get all those blocks then get all the records in wrappers with a list of headers and a list of those sobjects.

Then I have a visualforce page that use repeat vf command :

  • repeat on all wrappers to create tables
  • repeat on all headers to create the table header then fill the rows & 1st column is a link to the record

This way my team can work on only one screen with data we want.

But I would like to be able to format the output value, depending on the type. Obviously for dates and datetimes.

I am just thinking about one thing : I could use a map of headers instead of a list, something like:

key = header, value = type. GetHeaders => return List<String>(headers.keySet()) 

So in my columns i could check the type to use some formated output values.

Source Link
Guillaume
  • 115
  • 1
  • 13

VF dynamic table of SObjects (cols = fields) - how to check type to apply format (dates ...)

I want to allow my team to display some leads and tasks (and any know object) with custom conditions and display all the data on only one screen. I made some custom objects "blocks" containing SOQL elements :

  • base query ; ex: select * from lead where createdDate = TODAY
  • headers ; ex: Name, CreatedDate, id

I have a controller that get all those blocks then get all the records in wrappers with a list of headers and a list of those sobjects.

Then I have a visualforce page that use repeat vf command :

  • repeat on all wrappers to create tables
  • repeat on all headers to create the table header then fill the rows & 1st column is a link to the record

This way my team can work on only one screen with data we want.

But I would like to be able to format the output value, depending on the type. Obviously for dates and datetimes.

Is there a way I can acheive this ?

I am just thinking about one thing : I could use a map of headers instead of a list, key = header, value = type. GetHeaders => return List(headers.keySet()) So in my columns i could check the type to use some formated output values.

Any other idea ?

Thanks :)