现在做的项目代码是原来其他公司做的,要在原来基础上业务进行适当调整加上一些CR,其中有一个需要调整的需求如下:

原来使用apex:selectCheckboxes封装了一个checkbox列表,因为数据太多导致显示起来比较丑,用户希望改进一下UI。

apex:selectCheckboxes作用原理为解析成html以后变成table标签,

大概层级结构可以分成<table><tbody><tr><td><input type="checkbox"/><label></td></tr></tbody></table>.并且每一个checkbox作为一个tr存在。

原来的代码演示如下:

Apex:模拟50个checkbox的列表

 public with sharing class SelectCheckboxesController {

     public List<SelectOption> options{get;set;}

     public Integer optionSize{get;set;}

     public SelectCheckboxesController() {
options = new List<SelectOption>();
for(Integer i=0;i<50;i++) {
options.add(new SelectOption(String.valueOf(i),String.valueOf(i)));
}
optionSize = options.size();
} }

Visualforce Page:显示数据

 <apex:page controller="SelectCheckboxesController" sidebar="true">
<apex:form >
<apex:outputPanel id="xxPanel">
<apex:selectCheckboxes layout="pageDirection" styleClass="xxStyle" id="xxId" rendered="{!optionSize > 0}">
<apex:selectOptions value="{!options}"/>
</apex:selectCheckboxes>
<apex:outputLabel value="无复选框列表" rendered="{!optionSize == 0}"/>
</apex:outputPanel> </apex:form>
</apex:page>

此种方式显示效果如下所示:

此种方式对于用户选择来说确实不方便,显示也不够美观,因为数据量多但是每行只显示一条数据。

想出来的解决方案有两个,一种是扩展列数,比如每行显示4列,另一种是新增搜索功能,通过搜索筛选符合条件的数据。

一.扩展列数,每行显示4列数据

原来的控件仅支持单列,如果扩展列数,则需要使用其他控件,比如pageblocktable或者html中的table,使用apex:repeat渲染,这里使用第二种

Apex代码:

public with sharing class SelectCheckListController {

    public Integer itemSize{get;set;}

    public Integer itemSizeDown{get;set;}

    public List<Item> itemList{get;set;}

    public SelectCheckListController() {
init();
} public void init() {
List<String> tempItemList = new List<String>();
for(Integer i=0;i < 100;i ++) {
tempItemList.add('item ' + String.valueOf(i));
}
itemList = new List<Item>();
Decimal itemListSizeDouble = Decimal.valueOf(tempItemList.size()) / 4;
itemSize = Integer.valueOf(itemListSizeDouble.round(System.RoundingMode.CEILING));
itemSizeDown = Integer.valueOf(itemListSizeDouble.round(System.RoundingMode.DOWN));
for(Integer i = 0;i < itemSize;i++) {
Item tempItem = new Item();
if(i * 4 < tempItemList.size()) {
tempItem.item1 = tempItemList.get(i * 4);
}
if(4 * i + 1 < tempItemList.size()) {
tempItem.item2 = tempItemList.get(i* 4 + 1);
}
if(4 * i + 2 < tempItemList.size()) {
tempItem.item3 = tempItemList.get(i * 4 + 2);
}
if(4 * i + 3 < tempItemList.size()) {
tempItem.item4 = tempItemList.get(i* 4 + 3);
}
itemList.add(tempItem);
}
} public class Item {
public String item1{get;set;}
public String item2{get;set;}
public String item3{get;set;}
public String item4{get;set;}
}
}

Visualforce Page:

 <apex:page controller="SelectCheckListController">
<apex:form >
<table>
<apex:repeat value="{!itemList}" var="ite">
<tr>
<td width="100px">{!ite.item1}<apex:inputCheckbox value="{!ite.item1}"/></td>
<td width="100px">{!ite.item2}<apex:inputCheckbox value="{!ite.item2}"/></td>
<td width="100px">{!ite.item3}<apex:inputCheckbox value="{!ite.item3}"/></td>
<td width="100px">{!ite.item4}<apex:inputCheckbox value="{!ite.item4}"/></td>
</tr>
</apex:repeat>
</table>
</apex:form>
</apex:page>

此种方式显示效果如下:

此种方式设计出来的样式其实没有太大的作用,如果每个item的value长度不同,则显示效果很丑,所以添加搜索框,过滤数据方式显得更加符合要求。

二.过滤数据:

Apex代码:

  public class SimpleSelectCheckboxesController {
public List<SelectOption> options{get;set;} public Integer optionSize{get;set;} public List<SelectOption> optionsBackUp{get;set;} public String inputValue{get;set;} public SimpleSelectCheckboxesController() {
options = new List<SelectOption>();
optionsBackUp = new List<SelectOption>();
for(Integer i=0;i<100;i++) {
options.add(new SelectOption(String.valueOf(i),String.valueOf(i)));
}
optionSize = options.size();
optionsBackUp.addAll(options);
} public void doAction() {
options = new List<SelectOption>();
for(Integer i=0;i<optionsBackUp.size();i++) {
SelectOption option = optionsBackUp.get(i);
if(option.getLabel().contains(inputValue)) {
options.add(option);
}
}
optionSize = options.size();
}
}

Visualforce Page

 <apex:page controller="SimpleSelectCheckboxesController" sidebar="true">

 <apex:includeScript value="{!$Resource.JQuery2}"/>
<script type="text/javascript">
function showInfo() {
var value = $('.xxList').val();
doAction(value);
}
</script>
<apex:form >
<apex:inputText onkeyup="showInfo()" value="{!inputValue}" id="xxList" styleClass="xxList"/>
<apex:outputPanel id="xxPanel">
<apex:selectCheckboxes layout="pageDirection" styleClass="basicRequiresSelect" accesskey="basicRequireAccessKey" id="basic" rendered="{!optionSize > 0}">
<apex:selectOptions value="{!options}"/>
</apex:selectCheckboxes>
<apex:outputLabel value="无搜索结果,请重新输入查询条件" rendered="{!optionSize == 0}"/>
</apex:outputPanel> <apex:actionFunction action="{!doAction}" status="LoadingStatusSpinner" name="doAction" reRender="xxPanel" immediate="true">
<apex:param name="inputValue" value="" assignTo="{!inputValue}" />
</apex:actionFunction>
</apex:form>
</apex:page>

显示效果展示:

1.初始进入画面

2.模糊搜索显示结果布局

3.搜索内容不存在情况下布局

总结:此种方式并没有特别制作checkbox选中后往后台如何传值,感兴趣的伙伴可以自行玩耍。通过这个小需求的改造可以看出最开始设计项目的时候页面相关尽量选用灵活的一些控件,很多VF自带的控件限制特别多,如果项目需要经常页面改动的建议少量使用VF自带控件。如果checkbox列表有更加好的优化方案,欢迎留言。如果篇中有错误的地方欢迎指正。

salesforce 零基础学习(四十四)实现checkbox列表简单过滤功能的更多相关文章

  1. salesforce零基础学习(九十四)classic下pagelayout引入的vf page弹出内容更新此page layout

    我们在classic环境中,有时针对page layout不能实现的地方,可以引入 一个vf page去增强标准的 page layout 功能,有时可能要求这个 vf page的部分修改需要更新此 ...

  2. salesforce 零基础学习(十九)Permission sets 讲解及设置

    Permission sets以及Profile是常见的设置访问权限的方式. Profile规则为'who see what'.通过Profile可以将一类的用户设置相同的访问权限.对于有着相同Pro ...

  3. salesforce 零基础学习(十八)WorkFlow介绍及用法

    说起workflow大家肯定都不陌生,这里简单介绍一下salesforce中什么情况下使用workflow. 当你分配许多任务,定期发送电子邮件,记录修改时,可以通过自动配置workflow来完成以上 ...

  4. salesforce 零基础学习(十六)Validation Rules & Date/time

    上一篇介绍的内容为Formula,其中的Date/time部分未指出,此篇主要介绍Date/time部分以及Validation rules. 本篇参考PDF: Date/time:https://r ...

  5. salesforce 零基础学习(六十一)apex:component简单使用以及图片轮转播放的实现

    有的时候,我们项目有可能有类似需求:做一个简单的图像轮转播放功能,不同的VF页面调用可以显示不同的图片以及不同的图片描述.这种情况,如果在每个页面单独处理相关的图像轮转播放则显得代码特别冗余,此种情况 ...

  6. salesforce零基础学习(八十九)使用 input type=file 以及RemoteAction方式上传附件

    在classic环境中,salesforce提供了<apex:inputFile>标签用来实现附件的上传以及内容获取.salesforce 零基础学习(二十四)解析csv格式内容中有类似的 ...

  7. salesforce 零基础学习(五十二)Trigger使用篇(二)

    第十七篇的Trigger用法为通过Handler方式实现Trigger的封装,此种好处是一个Handler对应一个sObject,使本该在Trigger中写的代码分到Handler中,代码更加清晰. ...

  8. salesforce零基础学习(八十)使用autoComplete 输入内容自动联想结果以及去重实现

    项目中,我们有时候会需要实现自动联想功能,比如我们想输入用户或者联系人名称,去联想出系统中有的相关的用户和联系人,当点击以后获取相关的邮箱或者其他信息等等.这种情况下可以使用jquery ui中的au ...

  9. salesforce 零基础学习(六十八)http callout test class写法

    此篇可以参考: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restfu ...

随机推荐

  1. java调用sqlldr oracle 安装的bin目录

    package com.jyc.sqlldr; import java.io.BufferedReader;import java.io.InputStream;import java.io.Inpu ...

  2. 我理想中的父母(The Ideal Parents In My Heart)

    Parents are the first teachers in children's life, and people all know the great importance exactly ...

  3. time的用法

    线程计时器(System.Threading.Timer) System.Windows.Threading.DispatcherTimer tRecorderTimer; if (tRecorder ...

  4. NHibernate开发入门

    首先,我们了解一下ORM是什么?ORM指对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程 ...

  5. iOS Real Stuff

    Ray Wenderlich     AppCoda(English)   AppCoda(TW) Awesome iOS      Code4App代码库     CocoaChina代码库   o ...

  6. BZOJ3438 小M的作物(最小割)

    题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=3438 Description 小M在MC里开辟了两块巨大的耕地A和B(你可以认为 ...

  7. 关于handler 和 looper 的问题

    重新去学习回顾looper和handler ,还是需要重新认识这个经常使用的机制. 我首先是看任玉刚老师的书<android的开发艺术探索>的第十章. 里面一句话开始说出了我们大概的理解— ...

  8. BZOJ1120 : [POI2009]STR

    因为问题的对称性,只需要考虑求出有多少点离$A$更近即可. 枚举$4$个绝对值的正负号,可以解出坐标范围. 若可以转化为二维数点,则可以统一扫描线+树状数组解决. 否则是三维数点,按一维排序,剩下两维 ...

  9. SpringMvc的xml配置与annotation配置的例子的区别

    1.导入jar包时,要在xml配置基础上加 spring-aop-4.2.2.RELEASE.jar (注解的时候需要) 2.编写controller的时候要annotation需要做相关配置即红色部 ...

  10. WEB应用的组成结构