<apex:page Controller="ProductTablePageController" >
<apex:form id="form">
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:pageBlockSection columns="1">
<apex:inputText value="{!pr.Name}" />
<apex:inputText value="{!pr.Amount__c}" />
<apex:inputText value="{!pr.Price__c}" />
<apex:inputText value="{!pr.ProductType__c}" />
<apex:inputText value="{!pr.ReleaseDate__c }" />
<apex:inputText value="{!pr.Available__c}" />
<apex:inputText value="{!pr.AddedDate__c}" />
</apex:pageBlockSection>
<apex:commandButton action="{!insertNewProductTable}" value="Save"/>
</apex:pageBlockButtons>
<apex:selectList value="{!numberOfRowsToReturn}" size="1" >
<apex:selectOption itemLabel="1" itemValue="1" ></apex:selectOption>
<apex:selectOption itemLabel="2" itemValue="2"></apex:selectOption>
<apex:selectOption itemLabel="5" itemValue="5"></apex:selectOption>
<apex:selectOption itemLabel="10" itemValue="10"></apex:selectOption>
<apex:actionSupport event="onchange" reRender="form" action="{!updatePage}"/>>
</apex:selectList><br/>
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!Products}" var="pr" id="AccountData" >
<apex:column headerValue="Buttons">
<apex:commandLink value="Delete" action="{!deleteProductTable}"
onclick="if(!confirm('Are you sure?')) return false;">
<apex:param value="{!pr.Id}" name="idToDel" assignTo="{!SelectedProductId}"/>
</apex:commandLink>
<apex:commandLink value="Edit" action="{!updateNewProductTable}" />
</apex:column>
<apex:column headervalue="Name">
<apex:outputText value="{!pr.Name}" />
<apex:inputText value="{!pr.Name}" style="width:30px"/>
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Name" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column headervalue="Amount"><apex:outputText value="{!pr.Amount__c}" />
<apex:inputText value="{!pr.Amount__c}" style="width:30px"/>
</apex:column>
<apex:column headervalue="Price"><apex:outputText value="{!pr.Price__c}" />
<apex:inputText value="{!pr.Price__c}" style="width:30px"/>
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Price{!IF(sortExpression=='Price__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="Price__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column headervalue="ProductType"><apex:outputText value="{!pr.ProductType__c}" />
<apex:inputText value="{!pr.ProductType__c}" style="width:30px"/>
</apex:column>
<apex:column headervalue="ReleaseDate"><apex:outputText value="{!pr.ReleaseDate__c}" />
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="ReleaseDate{!IF(sortExpression=='ReleaseDate__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="ReleaseDate__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column headervalue="Available"><apex:outputText value="{!pr.Available__c}" />
</apex:column>
<apex:column headervalue="AddedDate"><apex:outputText value="{!pr.AddedDate__c}" />
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="AddedDate{!IF(sortExpression=='AddedDate__c',IF(sortDirection='ASC','▼','▲'),'')}">
<apex:param value="AddedDate__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
<apex:panelGrid columns="4">
<apex:commandLink action="{!first}">First</apex:commandlink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
<apex:commandLink action="{!last}">Last</apex:commandlink>
</apex:panelGrid>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom" >
<apex:inputText value="{!searchKey}" />
<apex:commandButton value="Search" action="{!searchProducts}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ProductTablePageController {
//variables are here
public Product_Table__c pr { get; set; }
public List<Product_Table__c> Products { get; set; }
public string SelectedProductId { get; set; }
public String Name {get; set;}
public Id editId {get; set;}
private String sortDirection = 'ASC';
private String sortExp = 'name';
public integer numberOfRowsToReturn {get; set;}
public String searchKey {get;set;}
//end variables
//Pagination start
public ApexPages.StandardSetController stCon{
get{
if(stCon == null){
stCon = new ApexPages.StandardSetController(Database.getQueryLocator([Select id,Name, Amount__c, Price__c,
ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ORDER BY Name ASC limit: numberOfRowsToReturn]));
stCon.setPageSize(3);
}
return stCon;
}
set;
}
public ProductTablePageController() {
setupProduct();
pr=new Product_Table__c();
numberOfRowsToReturn= 10;
}
public List<Product_Table__c> getProducts() {
return (List<Product_Table__c>)stCon.getRecords();
}
Public Boolean hasNext {
get { return stCon.getHasNext(); }
set;}public Boolean hasPrevious {
get { return stCon.getHasPrevious();}
set;}public Integer pageNumber {
get { return stCon.getPageNumber(); }
set; }public void first() {
stCon.first(); }
public void last() {
stCon.last(); }public void previous() {
stCon.previous(); }
public void next() {
stCon.next(); }
public void cancel() {
stCon.cancel(); }
//Pagination end
//edit product start here
public void init() {
Products = [Select id, Name, Amount__c, Price__c, ProductType__c,
ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ]; }
public PageReference updateNewProductTable() {
try{
update products; }
catch(DmlException ex){
ApexPages.addMessages(ex); }
init();
return null; }
//end edit product
public void setupProduct() {
Products = [Select id, Name, Amount__c, Price__c, ProductType__c,
ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ]; }
// insert new product operation
public PageReference insertNewProductTable() {
upsert pr;
pr=new Product_Table__c();
Products = [Select id,Name, Amount__c, Price__c, ProductType__c,
ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ];
return null; }
// insert new product operation
//delete product start here
public void deleteProductTable(){
Products = [Select id, Name, Amount__c, Price__c, ProductType__c,
ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c
where id = :SelectedProductId];
delete Products;
setupProduct(); }
//end delete product
//search product start here
public void searchProducts(){
string searchquery='select Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c where name like \'%' + searchKey + '%\' ';
products= Database.query(searchquery);
}
//end search product
//sorting start here
public String sortExpression
{ get
{ return sortExp; }
set{
//if the column is clicked on then switch between Ascending and Descending modes
if (value == sortExp)
sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value; } }public String getSortDirection()
{ //if not column is selected
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection; }public void setSortDirection(String value)
{ sortDirection = value; }
public PageReference ViewData() {
//build the full sort expression
string sortFullExp = sortExpression + ' ' + sortDirection;
//query the database based on the sort expression
products = Database.query('Select id, Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c order by ' + sortFullExp + ' limit 1000');
return null; }
//end sorting
public void updatePage() {
products.clear();
products=[select Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c,
Available__c, AddedDate__c from Product_Table__c LIMIT:numberOfRowsToReturn ]; }
}
[code][/code]Код пагинации рабочий. Если его вставить отдельно, то всё работает. Но внутри другого кода не работают кнопки first, next, last, previous. Подскажите пожалуйста в чём причина? [code] <apex:page Controller="ProductTablePageController" > <apex:form id="form"> <apex:pageBlock > <apex:pageBlockButtons location="top"> <apex:pageBlockSection columns="1"> <apex:inputText value="{!pr.Name}" /> <apex:inputText value="{!pr.Amount__c}" /> <apex:inputText value="{!pr.Price__c}" /> <apex:inputText value="{!pr.ProductType__c}" /> <apex:inputText value="{!pr.ReleaseDate__c }" /> <apex:inputText value="{!pr.Available__c}" /> <apex:inputText value="{!pr.AddedDate__c}" /> </apex:pageBlockSection> <apex:commandButton action="{!insertNewProductTable}" value="Save"/> </apex:pageBlockButtons> <apex:selectList value="{!numberOfRowsToReturn}" size="1" > <apex:selectOption itemLabel="1" itemValue="1" ></apex:selectOption> <apex:selectOption itemLabel="2" itemValue="2"></apex:selectOption> <apex:selectOption itemLabel="5" itemValue="5"></apex:selectOption> <apex:selectOption itemLabel="10" itemValue="10"></apex:selectOption> <apex:actionSupport event="onchange" reRender="form" action="{!updatePage}"/>> </apex:selectList><br/> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!Products}" var="pr" id="AccountData" > <apex:column headerValue="Buttons"> <apex:commandLink value="Delete" action="{!deleteProductTable}" onclick="if(!confirm('Are you sure?')) return false;"> <apex:param value="{!pr.Id}" name="idToDel" assignTo="{!SelectedProductId}"/> </apex:commandLink> <apex:commandLink value="Edit" action="{!updateNewProductTable}" /> </apex:column> <apex:column headervalue="Name"> <apex:outputText value="{!pr.Name}" /> <apex:inputText value="{!pr.Name}" style="width:30px"/> <apex:facet name="header"> <apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▼','▲'),'')}"> <apex:param value="Name" name="column" assignTo="{!sortExpression}" ></apex:param> </apex:commandLink> </apex:facet> </apex:column> <apex:column headervalue="Amount"><apex:outputText value="{!pr.Amount__c}" /> <apex:inputText value="{!pr.Amount__c}" style="width:30px"/> </apex:column> <apex:column headervalue="Price"><apex:outputText value="{!pr.Price__c}" /> <apex:inputText value="{!pr.Price__c}" style="width:30px"/> <apex:facet name="header"> <apex:commandLink action="{!ViewData}" value="Price{!IF(sortExpression=='Price__c',IF(sortDirection='ASC','▼','▲'),'')}"> <apex:param value="Price__c" name="column" assignTo="{!sortExpression}" ></apex:param> </apex:commandLink> </apex:facet> </apex:column> <apex:column headervalue="ProductType"><apex:outputText value="{!pr.ProductType__c}" /> <apex:inputText value="{!pr.ProductType__c}" style="width:30px"/> </apex:column> <apex:column headervalue="ReleaseDate"><apex:outputText value="{!pr.ReleaseDate__c}" /> <apex:facet name="header"> <apex:commandLink action="{!ViewData}" value="ReleaseDate{!IF(sortExpression=='ReleaseDate__c',IF(sortDirection='ASC','▼','▲'),'')}"> <apex:param value="ReleaseDate__c" name="column" assignTo="{!sortExpression}" ></apex:param> </apex:commandLink> </apex:facet> </apex:column> <apex:column headervalue="Available"><apex:outputText value="{!pr.Available__c}" /> </apex:column> <apex:column headervalue="AddedDate"><apex:outputText value="{!pr.AddedDate__c}" /> <apex:facet name="header"> <apex:commandLink action="{!ViewData}" value="AddedDate{!IF(sortExpression=='AddedDate__c',IF(sortDirection='ASC','▼','▲'),'')}"> <apex:param value="AddedDate__c" name="column" assignTo="{!sortExpression}" ></apex:param> </apex:commandLink> </apex:facet> </apex:column> </apex:pageBlockTable> <apex:panelGrid columns="4"> <apex:commandLink action="{!first}">First</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink> <apex:commandLink action="{!last}">Last</apex:commandlink> </apex:panelGrid> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom" > <apex:inputText value="{!searchKey}" /> <apex:commandButton value="Search" action="{!searchProducts}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> [/code] [code] public class ProductTablePageController { //variables are here public Product_Table__c pr { get; set; } public List<Product_Table__c> Products { get; set; } public string SelectedProductId { get; set; } public String Name {get; set;} public Id editId {get; set;} private String sortDirection = 'ASC'; private String sortExp = 'name'; public integer numberOfRowsToReturn {get; set;} public String searchKey {get;set;} //end variables //Pagination start public ApexPages.StandardSetController stCon{ get{ if(stCon == null){ stCon = new ApexPages.StandardSetController(Database.getQueryLocator([Select id,Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ORDER BY Name ASC limit: numberOfRowsToReturn])); stCon.setPageSize(3); } return stCon; } set; } public ProductTablePageController() { setupProduct(); pr=new Product_Table__c(); numberOfRowsToReturn= 10; } public List<Product_Table__c> getProducts() { return (List<Product_Table__c>)stCon.getRecords(); } Public Boolean hasNext { get { return stCon.getHasNext(); } set;} public Boolean hasPrevious { get { return stCon.getHasPrevious();} set;} public Integer pageNumber { get { return stCon.getPageNumber(); } set; } public void first() { stCon.first(); } public void last() { stCon.last(); } public void previous() { stCon.previous(); } public void next() { stCon.next(); } public void cancel() { stCon.cancel(); } //Pagination end //edit product start here public void init() { Products = [Select id, Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ]; } public PageReference updateNewProductTable() { try{ update products; } catch(DmlException ex){ ApexPages.addMessages(ex); } init(); return null; } //end edit product public void setupProduct() { Products = [Select id, Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ]; } // insert new product operation public PageReference insertNewProductTable() { upsert pr; pr=new Product_Table__c(); Products = [Select id,Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c ]; return null; } // insert new product operation //delete product start here public void deleteProductTable(){ Products = [Select id, Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c where id = :SelectedProductId]; delete Products; setupProduct(); } //end delete product //search product start here public void searchProducts(){ string searchquery='select Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c where name like \'%' + searchKey + '%\' '; products= Database.query(searchquery); } //end search product //sorting start here public String sortExpression { get { return sortExp; } set{ //if the column is clicked on then switch between Ascending and Descending modes if (value == sortExp) sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC'; else sortDirection = 'ASC'; sortExp = value; } } public String getSortDirection() { //if not column is selected if (sortExpression == null || sortExpression == '') return 'ASC'; else return sortDirection; } public void setSortDirection(String value) { sortDirection = value; } public PageReference ViewData() { //build the full sort expression string sortFullExp = sortExpression + ' ' + sortDirection; //query the database based on the sort expression products = Database.query('Select id, Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c order by ' + sortFullExp + ' limit 1000'); return null; } //end sorting public void updatePage() { products.clear(); products=[select Name, Amount__c, Price__c, ProductType__c, ReleaseDate__c, Available__c, AddedDate__c from Product_Table__c LIMIT:numberOfRowsToReturn ]; } } [/code]
Последняя иконка в редакторе позволяет вставить в текст код чтобы он выглядел по человечиски.
Начните с оформления вопроса чтобы получить ответ. Читать портянки кода, а к тому же пытаться их воспроизвести никто здесь не будет.
Последняя иконка в редакторе позволяет вставить в текст код чтобы он выглядел по человечиски. Начните с оформления вопроса чтобы получить ответ. Читать портянки кода, а к тому же пытаться их воспроизвести никто здесь не будет.