标准组件:
action:调用的后台方法
assignTo:
reRender:刷新
<apex:page controller="PartsSearchAndManagementController" tabStyle="Parts__c"> <html> <body> <script type="text/javascript"> function del(Id){ if(confirm("确认删除吗")){ delParts(Id); }else{ } } </script> </body> </html> <apex:form > <apex:pageBlock id="sblock"> <apex:pageBlockSection title="检索条件" columns="2" collapsible="false"> <apex:outputPanel > 部件型号:<apex:inputText value="{!PartsModel}" /> 状态:<apex:selectList label="状态" value="{!SelectStatus}" size="1"> <apex:selectOption itemValue="全部" itemLabel="全部"></apex:selectOption> <apex:selectOption itemValue="缺货" itemLabel="缺货"></apex:selectOption> <apex:selectOption itemValue="已预约" itemLabel="已预约"></apex:selectOption> <apex:selectOption itemValue="已出库" itemLabel="已出库"></apex:selectOption> <apex:selectOption itemValue="可使用" itemLabel="可使用"></apex:selectOption> </apex:selectList> <apex:commandButton value="查询" action="{!SearchAction}" status="pgstatus" reRender="sblock"/> </apex:outputPanel> <apex:outputLink id="test" value="/00O5D000000OL3s" target="_blank">导出采购清单</apex:outputLink> </apex:pageBlockSection> <apex:pageBlockSection title="检索结果" columns="1" collapsible="false"> <apex:pageBlockTable value="{!partList}" var="part" id="sresult"> <apex:column headerValue="操作"> <apex:commandLink action="{!editAction}" value="编辑" target="_blank"> <apex:param assignTo="{!editId}" name="first" value="{!part.Id}"/> </apex:commandLink> <apex:outputText value=" | " /> <a class="DeleteParts" href="javascript:;" onclick="del('{!part.Id}')">删除</a> <!--<apex:commandLink action="{!deleteAction}" value="删除" status="pgstatus" reRender="sresult" onclick="del()"> <apex:param assignTo="{!deleteId}" name="first" value="{!part.Id}"/> </apex:commandLink>--> </apex:column> <apex:column value="{!part.Name}"/> <apex:column value="{!part.PartsModel__c}"/> <apex:column value="{!part.Status__c}"/> <apex:column headerValue="工作订单"> <apex:outputLink value="/{!part.WorkOrder__r.Id}" target="_parent">{!part.WorkOrder__r.WorkOrderNumber__c}</apex:outputLink> </apex:column> <!--<apex:column value="{!part.WorkOrder__c}"/>--> <apex:column value="{!part.SPPrice__c}"/> <apex:column value="{!part.Position__c}"/> <apex:column value="{!part.STContractNo__c}"/> <apex:column value="{!part.LotNo__c}"/> <apex:column value="{!part.Special__c}"/> <apex:column value="{!part.Comments__c }"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> <apex:actionFunction name="delParts" action="{!deleteAction}" reRender="sresult"> <apex:param assignTo="{!deleteId}" name="deleteId" value=""/> </apex:actionFunction> <apex:actionStatus id="pgstatus"> <apex:facet name="start"> <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.25; z-index: 1000; background-color: black;"> </div> <div style="position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 1001; margin: 15% 50%"> <div style="display: inline-block; padding: 2px; background-color: #fff; 125px;"> <img src="/img/loading.gif" style="float: left; margin: 8px;" /> <span style="display: inline-block; padding: 10px 0px;">Please Wait...</span> </div> </div> </apex:facet> </apex:actionStatus> </apex:form> </apex:page>
Apex Class
public with sharing class PartsSearchAndManagementController { public String deleteId {get; set;}//删除 public String editId {get; set;}//编辑 public String PartsModel{get;set;}//查询型号 public String SelectStatus{get;set;} public List<Parts__c> partList {get; set;} public List<Parts__c> TotalpartList {get; set;} public PartsSearchAndManagementController() { /* partList = [SELECT Id,PartsModel__c,SPPrice__c, Name, Position__c,WorkOrder__c,LotNo__c,Status__c,STContractNo__c,Comments__c,Special__c FROM Parts__c ORDER BY CreatedDate desc limit 1000]; DisplayData(partList); */ } //得到要展示的所有数据 public void DisplayData(List<Parts__c> pList){ set<Id> SetId=new set<Id>(); for(Parts__c par:pList){ if(par.Id != null){ SetId.add(par.Id); } } } public void SearchAction(){ String SearchPart = 'SELECT Id,PartsModel__c,SPPrice__c, Name, Position__c,WorkOrder__c,WorkOrder__r.WorkOrderNumber__c,LotNo__c,Status__c,STContractNo__c,Comments__c,Special__c FROM Parts__c '; if(PartsModel != null && SelectStatus == '全部'){ String PModel = '%' + PartsModel + '%'; SearchPart +='Where Name like :PModel ORDER BY CreatedDate desc limit 1000 '; partList = Database.query(SearchPart); // DisplayData(partList); }else if(PartsModel != null && SelectStatus != '全部' ){ String PModel = '%' + PartsModel + '%'; SearchPart +='Where Name like :PModel AND Status__c =: SelectStatus ORDER BY CreatedDate desc limit 1000'; partList = Database.query(SearchPart); // DisplayData(partList); } } //编辑 public PageReference editAction(){ system.debug('editId: ' + editId); if (editId != null && editId != ''){ //这里是跳转到编辑页面 因为是标准的页面 所以('/'+editId+'/e?retURL=%2F'+ editId) 是固定的写法 return new PageReference('/'+editId+'/e?retURL=%2F'+ editId); }else{ return null; } } //删除 public PageReference deleteAction(){
//获取页面的值 //deleteId = system.currentPageReference().getParameters().get('deleteId'); system.debug('deleteId : ' + deleteId ); if (deleteId != null && deleteId != '') { //这里是查询你要删除的记录 Parts__c pc= [Select Id From Parts__c Where Id =: deleteId]; delete pc; SearchAction(); /*这个是重新初始化要展示的数据 partList = [SELECT Id,PartsModel__c,SPPrice__c, Name, Position__c,WorkOrder__c,LotNo__c,Status__c,STContractNo__c,Comments__c,Special__c FROM Parts__c]; DisplayData(partList); //这个是删除后重新刷新页面 return new PageReference('/apex/PartsSearchAndManagement'); */ } return null; } }