Salesforce在Visualforce组件上保留了1000个限制,因为大型数据表的重新渲染性能非常差,可能会导致浏览器冻结,需要注意。
使用上述解决方法后,您需要注意的限制是
堆大小,因为列表开始变得很大。如果数据太大,建议使用过滤(在
SOQL
上)来减少需要返回到浏览器的数据。(
Select2
可以解决这个问题)
有几种解决方法。以下是其中的一些...
- 使用行和第一个参数设置显示数据的偏移量和限制:
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="0">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="1000">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="2000">
{!item.text}
</apex:repeat>
-使用包装器:
Visualforce页面:
<apex:page controller="thousandLimit">
<apex:pageBlock >
<apex:repeat value="{!thousandBlocks}" var="block">
<apex:pageBlockTable value="{!block.Accounts}" var="a">
<apex:column value="{!a.Name}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:pageBlock>
</apex:page>
控制器:
public class thousandLimit
{
private limitWrapper[] thousandBlocks = new limitWrapper[]{};
private final integer listLimit;
public thousandLimit()
{
listLimit = 999;
}
public limitWrapper[] getthousandBlocks()
{
thousandBlocks = new limitWrapper[]{};
integer counter = 0;
integer loopCount = 0;
Account[] tmpAccount = new Account[]{};
for(Account a:[SELECT Id, Name FROM Account])
{
if(counter < listLimit)
{
tmpAccount.add(a);
counter++;
}
else
{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpAccount,loopCount));
tmpAccount = new Account[]{};
tmpAccount.add(a);
counter = 0;
}
}
if(thousandBlocks.size() == 0)
{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpAccount,loopCount));
}
return thousandBlocks;
}
public class limitWrapper
{
public Account[] accounts {get;set;}
public integer blockNumber {get;set;}
public limitWrapper(Account[] accs, integer i)
{
accounts = accs;
blockNumber = i;
}
}
}
-您可以使用readonly
标签将其从1k增加到10k:
<apex:page controller="thousandLimit" readonly="true">
<apex:pageBlock >
<apex:repeat value="{!thousandBlocks}" var="block">
<apex:pageBlockTable value="{!block.cases}" var="c">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.owner.name}"/>
<apex:column value="{!c.App_Process__c}"/>
<apex:column value="{!c.Load__c}"/>
<apex:column value="{!c.subject}"/>
<apex:column value="{!c.Estimated_Completion_Date__c}"/>
<apex:column value="{!c.Complete__c}"/>
<apex:column value="{!c.Priority}"/>
<apex:column value="{!c.Case_Age_Days__c}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:pageBlock>
</apex:page>