欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

程序员文章站 2022-05-19 13:38:37
...

创建对象:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 

 

首页(he.vfp):

<apex:page StandardController="meili__c" extensions="cc" sidebar="false" showHeader="false" >
    <apex:stylesheet value="{!$Resource.style}"/>
    <apex:includeScript value="{!$Resource.tijiao}"/>
    <div class="head">
        哈哈哈哈哈标题
    </div>
    <div class="bodd">
        <div class="left">
            左侧:<button id="dianji" onclick="OpenDialog()">点击</button>
        </div>
        <div class="right">
            
            <apex:form id="shaixuan">
                <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="shaixuan">
                    <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
                </apex:actionFunction>
                
                <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="shaixuan">
                    <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
                </apex:actionFunction>
                
                <apex:actionFunction name="quanxuanzhong" action="{!xuan}" rerender="shaixuan">
                    <apex:param name="xuanstring" value="" assignTo="{!xuanstring}"/>
                </apex:actionFunction>
                
                <apex:actionFunction name="quanbuxuan" action="{!buxianxuan}" rerender="shaixuan">
                    <apex:param name="buxuanstring" value="" assignTo="{!buxuanstring}"/>
                </apex:actionFunction>
                
                <div>
                    筛选条件:
                    <apex:selectList value="{! optionAcc }" size="1">
                        <apex:selectOptions value="{!optionAccList }"/>
                        <apex:actionSupport event="onchange" action="{!searchAccOppList}" reRender="shaixuan"/>
                    </apex:selectList>
                </div>
                <div>
                    数据显示:
                </div>
                
                <apex:pageBlock >
                    <apex:pageBlockTable value="{!meimei}" var="mei">
                        <apex:column width="2%" >
                            <apex:facet name="header">
                                <apex:inputCheckbox onclick="selectAllCheckboxes1(this,'invId')" id="all" />
                            </apex:facet>
                            <apex:inputCheckbox value="{!mei.IsSelected}" id="invId" onchange="doCheckboxChange(this,'{!mei.meili.meiliID__c}')"/>
                            <!-- <apex:actionSupport event="onclick" action="{!inp}" reRender="shaixuan"/> -->
                        </apex:column>
                        <apex:column value="{!mei.meili.meiliID__c}"/>
                        <apex:column value="{!mei.meili.meiliName__c}"/>
                        <apex:column value="{!mei.meili.meiliFen__c}"/>
                        <apex:column value="{!mei.meili.meiliTime__c}"/>
                        <apex:column value="{!mei.meili.meiliNote__c}"/>
                        <apex:column value="{!mei.meili.fenlei__c}"/>
                        <apex:column width="4%" >
                            <apex:facet name="header">
                                操作
                            </apex:facet>
                            <apex:commandLink value="修改" action="{!xiu}">
                                <apex:param name="xiuid" value="{!mei.meili.meiliID__c}"></apex:param>
                            </apex:commandLink>
                        </apex:column>
                        
                    </apex:pageBlockTable>
                </apex:pageBlock>
                
                
                <table style="width: 100%"><tr>
                    <td>
                        <apex:outputText value=" {!PageNumber}/{! CEILING(ResultSize / size) }"/>
                    </td>
                    <td align="center">
                        <!-- Previous page -->
                        <!-- active -->
                        <apex:commandLink action="{!first}" value="« 首页"/>
                        
                        <apex:commandLink action="{!Previous}" value="« Previous"
                                          rendered="{! HasPrevious }"/>
                        <!-- inactive (no earlier pages) -->
                        <apex:outputText style="color: #ccc;" value="« Previous"
                                         rendered="{! NOT(HasPrevious) }"/>
                        &nbsp;&nbsp;
                        <!-- Next page -->
                        <!-- active -->
                        <apex:commandLink action="{!Next}" value="Next »"
                                          rendered="{!HasNext}"/>
                        <!-- inactive (no more pages) -->
                        <apex:outputText style="color: #ccc;" value="Next »"
                                         rendered="{!NOT(HasNext)}"/>
                        
                        <apex:commandLink action="{!last}" value="尾页 »" />
                        
                    </td>
                    <td align="right">
                        <apex:selectList value="{!size}" size="1">
                            <apex:selectOption itemValue="3" itemLabel="3"/>
                            <apex:selectOption itemValue="5" itemLabel="5"/>
                            <apex:selectOption itemValue="10" itemLabel="10"/>
                            <apex:selectOption itemValue="15" itemLabel="15"/>
                            <apex:selectOption itemValue="20" itemLabel="20"/>
                            <apex:actionSupport event="onchange" action="{!refreshPage}" reRender="shaixuan"/>
                        </apex:selectList>
                    </td>
                    </tr></table>                
                <apex:outputPanel >
                    <apex:commandButton value="新增数据" action="{!tiao}"/>
                </apex:outputPanel>
                
                <!--<apex:outputPanel >
<apex:commandButton value="修改数据" action="{!xiu}"/>
<apex:param name="xiuid" value="{!meili__c.meiliID__c}"></apex:param>
</apex:outputPanel>  -->
                
                <apex:outputPanel >
                    <apex:commandButton value="删除" action="{!piliangdel}"/>
                </apex:outputPanel>
                
                
                
            </apex:form>
        </div>
    </div>
    <div class="clear"></div>
</apex:page>

 

首页后台(cc.apxc):

public with sharing class cc  {
    List<meiliji> Meimei{get;set;}
    public String optionAcc {get; set;}
    public List<SelectOption> optionAccList {get; set;}
    public List<String> result {get;set;}
    public String xuanzhong {get;set;}
    
    public static final Integer DEFAULT_PAGE_SIZE = 5;
    public Integer size {get;set;} 
    public String filterId {get;set;}
    public List<SelectOption> listViewOptions {get;set;}
    public List<meili__c> tpList;
    public Set<Id> tpIds;
    public String query;
    
    private Set<String> selectedContactIds;
    private ApexPages.StandardSetController setCon;
    public String contextItem{get;set;}
    
    public String xuanstring{get;set;}
    private List<String> xuanlist;
    private Set<String> xuanset;
    
    public String buxuanstring{get;set;}
    private List<String> buxuanlist;
    
    public cc(ApexPages.StandardController stdController){
        getTaskTypes();
        this.selectedContactIds= new Set<String>();
        this.xuanset= new Set<String>();
        query = 'select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c,meili__c.fenlei__c FROM meili__c order by meili__c.meiliID__c';
        this.setCon= new ApexPages.StandardSetController(Database.getQueryLocator(query));
        size = DEFAULT_PAGE_SIZE;
        this.setCon.setPageSize(size);
    }

    // 返回自定义对象Tender_Project__c的List数据集合
    public List<meiliji> getMeimei() {
        List<meiliji> rows = new List<meiliji>();
        for(sObject r : this.setCon.getRecords()){
            meili__c mm = (meili__c)r;
            meiliji row = new meiliji(mm,false);
            //System.debug('单独选'+this.selectedContactIds);
            //System.debug('全选list'+this.xuanlist);
            //System.debug('全选set'+this.xuanset);
            
            if(this.selectedContactIds.contains(mm.meiliID__c)){
                row.IsSelected=true;
            }
            else{
                row.IsSelected=false;
            }
            rows.add(row);
        }
 
        return rows;
    }
    
    // 返回页面是否有下一页布尔值
    public Boolean hasNext {
        get {
            return setCon.getHasNext();
        }
        set;
    }
    
    // 返回页面是否有上一页布尔值
    public Boolean hasPrevious {
        get {
            return setCon.getHasPrevious();
        }
        set;
    }
    
    // 返回当前记录的页面数
    public Integer pageNumber {
        get {
            return setCon.getPageNumber();
        }
        set;
    }
    
    // 返回记录的总条数
    public Integer resultSize {
        get {
            return setCon.getResultSize();
        }
        set;
    }
    
    // 返回上一页记录
    public void previous() {
        setCon.previous();
    }
    
    // 返回下一页记录
    public void next() {
        setCon.next();
    }
    
    //首页
    public void first() {
        setCon.first();
    }
    
    //尾页
    public void last() {
        setCon.last();
    }
    
    
    // 改变每一页显示的记录条数
    public void refreshPage() {
         setCon.setPageSize(size);
    }
    
    public void doSelectItem(){
        this.selectedContactIds.add(this.contextItem);
    }
    
     public void doDeselectItem(){
        this.selectedContactIds.remove(this.contextItem);
    }
    
    public void xuan(){
        this.xuanlist =  this.xuanstring.split(',');
        for(String qq : this.xuanlist){
            this.xuanset.add(qq);
        }
        this.selectedContactIds.addAll(this.xuanset);
    }
    
    public void buxianxuan(){
        System.debug('不不不不不不');
        System.debug(this.buxuanstring);
        this.buxuanlist =  this.buxuanstring.split(',');
        System.debug('不选'+this.buxuanlist);
        for(String qq : this.buxuanlist){
            this.selectedContactIds.remove(qq);
        }
    }
    
    
    
    //跳转到插入页
    public PageReference tiao(){
        PageReference pageRef = new PageReference('/apex/z12');
        return pageRef;
    }
    
    //下拉筛选
    public void getTaskTypes(){
        result = new List<String>();
        Schema.DescribeFieldResult fieldResult = meili__c.fenlei__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
        {
            result.add(f.getLabel());
        }
        optionAccList = new List<SelectOption>();
        if(result != null && !result.isEmpty()){
            optionAccList.add(new SelectOption('none', '全部'));
            for(String acc : result){
                optionAccList.add(new SelectOption(acc, acc));  
            }
        }
    }
    
    //筛选onchange
    public void searchAccOppList(){
        if(optionAcc!='none'){
             string queryStr = '%' + optionAcc + '%';
        query = 'select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c,meili__c.fenlei__c '
            +'from meili__c '
            +'where meili__c.fenlei__c LIKE :queryStr';
        }
        else{
        query = 'select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c,meili__c.fenlei__c '
            +'from meili__c ';
        }
        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        setCon.setPageSize(size);
    }
    
    //带参数跳转到修改页面
    public PageReference xiu(){
        String xid = ApexPages.currentPage().getParameters().get('xiuid');
        meili__c selectmeili = ([select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c from meili__c where meili__c.meiliID__c=:xid]);
        PageReference pageRef = new PageReference('/apex/bianji?xid='+ xid);
        return pageRef;
    }
    
    //批量删除数据
    public void piliangdel(){
        List<String> bb = new List<String>();
        for(String aa : selectedContactIds){
            bb.add(aa);
        }
        List<meili__c> ass = new List<meili__c>();
        ass = ([select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c,meili__c.fenlei__c FROM meili__c order by meili__c.meiliID__c]);
        
        for(meili__c zx :ass){
            for(String zf :bb){
                if(zx.meiliID__c == zf){
                    delete zx;
                }
            }
        }
        //for (meili__c mm : Meimei){
        //    system.debug(mm.ckk__c);
        //    if(mm.ckk__c){ 
        //        system.debug('hahah');
        //        delete mm;
        //    }
        //}
        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        setCon.setPageSize(size);
        //Meimei = (List<meili__c>)setCon.getRecords();
    }
  
    public with sharing class meiliji{
        public meili__c meili{get;set;}
        public Boolean IsSelected{get;set;}
        public meiliji(meili__c mm, Boolean ck){
            this.meili=mm;
            this.IsSelected=ck;
        }
    }
  
}

 

新增页面(z12.vfp):

<apex:page StandardController="meili__c" extensions="z11">
    
    <apex:includeScript value="{!URLFOR($Resource.data,'layDate-v5.0.9/laydate/laydate.js')}"/>
    <apex:includeScript value="{!$Resource.tijiao}"/>
    <apex:stylesheet value="{!$Resource.style}"/>
    
    <apex:pageBlock title="新页面">
        <apex:pageBlockSection title="新增数据">
            <apex:form >
                
                <apex:pageMessages />
                
                <!--<apex:pageBlockSection >
                    美丽ID:<apex:inputField value="{!meili__c.meiliID__c}"/>   
                </apex:pageBlockSection>-->
                
                <apex:pageBlockSection >
                   <apex:inputField value="{!meili__c.meiliName__c}"/> 
                </apex:pageBlockSection>
                
                <apex:pageBlockSection >
                    <apex:inputField value="{!meili__c.meiliFen__c}"/> 
                </apex:pageBlockSection>
                
                <apex:pageBlockSection >
                    
                    <th class="labelCol vfLabelColTextWrap  first  last " scope="row">
                        <label for="j_id0:j_id4:j_id5:j_id6:j_id43:j_id44">分类</label>
                    </th>
                    <apex:selectList value="{! optionAcc }" size="1">
                        <apex:selectOptions value="{!optionAccList }"/>
                </apex:selectList>
                    
                </apex:pageBlockSection>
                
                
                
                <apex:pageBlockSection >
                   <apex:inputField value="{!meili__c.meiliTime__c}"/>
                </apex:pageBlockSection>
                <apex:pageBlockSection >
                    <apex:inputField value="{!meili__c.meiliNote__c}" />
                </apex:pageBlockSection>
                
                <apex:outputPanel >
                    <apex:commandButton value="确认新增" action="{!inser}"/>
                </apex:outputPanel>
                
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 

新增后台(z11.apxc):

public with sharing class z11 {
    private final  meili__c bn;
    public String optionAcc {get; set;}
    public List<SelectOption> optionAccList {get; set;}
    public List<String> result {get;set;}

    public z11(ApexPages.StandardController stdController){
        getTaskTypes();
        this.bn = (meili__c)stdController.getRecord();
        //this.bn.meiliTime__c.addError('时间错误');
        //this.bn.meiliName__c.addError('名称错误');
        
        //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'gggg'));
    }
    //public String meiliid{get;set;}
    //public String meiliname{get;set;}
    //public Integer meilifen{get;set;}
    //public Date meilitime{get;set;}
    //public String meilinote{get;set;}
    //
    
    public void getTaskTypes(){
        result = new List<String>();
        Schema.DescribeFieldResult fieldResult = meili__c.fenlei__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
        {
            result.add(f.getLabel());
        }
        optionAccList = new List<SelectOption>();
        if(result != null && !result.isEmpty()){
            optionAccList.add(new SelectOption('', '--None--'));
            for(String acc : result){
                optionAccList.add(new SelectOption(acc, acc));  
            }
        }
    }
    
    public PageReference inser(){
        
        meili__c ins = new meili__c();
        ins.meiliName__c = this.bn.meiliName__c;
        ins.meiliFen__c = this.bn.meiliFen__c;
        ins.meiliTime__c = this.bn.meiliTime__c;
        ins.meiliNote__c = this.bn.meiliNote__c;
        ins.fenlei__c = optionAcc;
        Insert ins;
        PageReference pageRef = new PageReference('/apex/he');
        return pageRef;
    }
    
}

 

编辑页面(bianji.vfp):

<apex:page StandardController="meili__c" extensions="z13">

    <apex:includeScript value="{!URLFOR($Resource.data,'layDate-v5.0.9/laydate/laydate.js')}"/>
    <apex:includeScript value="{!$Resource.tijiao}"/>
    <apex:stylesheet value="{!$Resource.style}"/>

    <apex:pageBlock title="编辑页面">
        <apex:pageBlockSection title="编辑数据">
    <apex:form >
        <apex:pageBlockSection >
            美丽ID:<apex:inputText value="{!meiliid}" id="meili"/>   
        </apex:pageBlockSection>
        
        <apex:pageBlockSection >
             美丽name:<apex:inputText value="{!meiliname}"/>  
        </apex:pageBlockSection>
        
        <apex:pageBlockSection >
             美丽分值:<apex:inputText value="{!meilifen}"/> 
        </apex:pageBlockSection>
        
        <apex:pageBlockSection >
             时间: <apex:inputField value="{!meili__c.meiliTime__c}" />
        </apex:pageBlockSection>
        <apex:pageBlockSection >
             备注:<apex:inputText value="{!meilinote}"/>
        </apex:pageBlockSection>
        
        <apex:outputPanel >
        <apex:commandButton value="确认修改" action="{!upd}"/>
    </apex:outputPanel>

    </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 

编辑后台(z13.apxc):

public with sharing class z13 {
    private final  meili__c qiantai;
    public meili__c selectmeili {get;set;}
    public String meiliid{get;set;}
    public String meiliname{get;set;}
    public Integer meilifen{get;set;}
    public Date meilitime{get;set;}
    public String meilinote{get;set;}

    public z13(ApexPages.StandardController stdController){
        string xid = apexpages.currentPage().getParameters().get('xid'); 
	    selectmeili = ([select meili__c.ckk__c,meili__c.meiliID__c,meili__c.meiliName__c,meili__c.meiliFen__c,meili__c.meiliTime__c,meili__c.meiliNote__c from meili__c where meili__c.meiliID__c=:xid]);
        meiliid = selectmeili.meiliID__c;
        meiliname = selectmeili.meiliName__c;
        meilifen = (Integer)selectmeili.meiliFen__c;
        meilitime = selectmeili.meiliTime__c;
        meilinote = selectmeili.meiliNote__c;
        this.qiantai = (meili__c)stdController.getRecord();
        this.qiantai.meiliTime__c = selectmeili.meiliTime__c;
    }
    
    
    public PageReference upd(){
        selectmeili.meiliName__c = meiliname;
        selectmeili.meiliFen__c = meilifen;
        selectmeili.meiliTime__c = this.qiantai.meiliTime__c;
        selectmeili.meiliNote__c = meilinote;
        UPDATE selectmeili;
        PageReference pageRef = new PageReference('/apex/he');
        return pageRef;
    }
    
}

 

tijiao.js:


function selectAllCheckboxes1(obj, receivedInputID) 
  {
  	var ax ='';
      var inputCheckBox = document.getElementById('j_id0:shaixuan:j_id17:j_id18').getElementsByTagName('input');
      for (var i = 0; i < inputCheckBox.length; i++) {
          if (inputCheckBox[i].id.indexOf(receivedInputID) != -1) 
          {
              inputCheckBox[i].checked = obj.checked;
              ax += inputCheckBox[i].parentNode.nextSibling.children[0].innerText+',';
          }
      }

      if(obj.checked){
                quanxuanzhong(ax);
              }else{
                quanbuxuan(ax);
              }
  }


function doCheckboxChange(cb,itemId){
 
            if(cb.checked==true){
                aSelectItem(itemId);
            }
            else{
                aDeselectItem(itemId);
            }
 
}

 

style.css:

.head{
	width:100%;
	height:40px;
	background:pink;
	color:#000;
}
.bodd{
	width:100%;
	height:auto;
}
.left{
	width:10%;
	float:left;
	background:orange;
	color:#000;
	height:400px;
}
.right{
	width:90%;
	float:left;
	background:yellow;
	color:#000;
	height:400px;
}
.clear{
	clear:both;
}

 

显示效果:

首页全部:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 

首页筛选:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 首页分页默认改为3:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

首页全选:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 

新增页面:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 

修改页面:

Salesforce vf 自定义页面 增删改查+分页+全选+筛选 apex代码

 

 

 

相关标签: Salesforce