现在做的项目代码是原来其他公司做的,要在原来基础上业务进行适当调整加上一些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. python tkinter

    1. 在python3中使用 import tkinter 异常:no module named _tkinter apt-get install python-tk

  2. VBA实例收集

    1.工作表事件:固定制定区域激活,使之不能选择其他区域. Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target. ...

  3. asp.net dataset 判断是否为空 ?

    1,if(ds == null) 这是判断内存中的数据集是否为空,说明DATASET为空,行和列都不存在!! 2,if(ds.Tables.Count == 0) 这应该是在内存中存在一个DATASE ...

  4. Maven依赖包下载慢--阿里云让你飞

    当用maven下载依赖包的时候,用官方的镜像库,那慢的真是要死要死的.后来在网上搜到英国的库(也是慢的不行),国内的oschina更是直接没法下载呀.不过还好突然发现阿里云也有镜像库,尝试了以下,速度 ...

  5. lamp

      Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立 的程序,但是因为常被放在一起使用,拥有了越来越高的 ...

  6. 在树霉派上配置LAMP

    apache2 配置文件: /etc/apache2/sites-enabled下的000-default.conf <VirtualHost *:> # The ServerName d ...

  7. linux菜鸟日记(3)

    Centos7利用shell编辑一串 一键完成一些基础配置的代码: 在这串shell代码中我实现了  IP地址的配置.光盘的挂载.本地yum源的搭建.一些服务的安装例如 httpd. php. ntp ...

  8. 第三周作业(三):wc程序

    本程序实现了统计文本档案中,文本单词数.字符数以及行数. 代码如下: #include<stdio.h> #include<stdlib.h> int linestatisti ...

  9. 利用浏览器LocalStorage缓存图片,视频文件

    文章路径:https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/

  10. 让/etc/profile文件修改后立即生效

    方法1: 让/etc/profile文件修改后立即生效 ,可以使用如下命令: # .  /etc/profile 注意: . 和 /etc/profile 有空格 方法2: 让/etc/profile ...