function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vin_89vin_89 

on clicking on edit,field should be converted to edit

in this,i am referring two pages ,first one is to search for the products and add it to shopping cart in other page,now in other page i need some funtionality:

1.on delete , that item would be removed from cart and should display remaining items.

2.on edit, Quantity field should be converted to input field

3.on change of quantiy, amount should be updated.

i was able to implement delete,nut i m not able to implement 2 and 3,can anyone please resolve this issue.

it would be better if anyone could modify the code.

 

<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageBlock id="myBlock" >
<apex:variable value="{!0}" var="rowNumber" />
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!back}" value="Back"/>
<apex:commandButton value="Place Order"/>
</apex:pageBlockButtons>
<apex:pageMessages />

<apex:pageBlockSection Title="SHOPPING CART" id="Selected_PBS">
<!-- Here we will use an extra variable to define a row number -->
<apex:outputPanel id="panelWithVar">
<apex:variable value="{!0}" var="rowNumber" />
</apex:outputPanel>

<apex:pageBlockTable value="{!SelectedProducts}" var="p" id="newItems" >
<!-- A button to remove individual entry.
We must to pass the line number to define a list entry number to remove -->
<apex:column width="5%">
<apex:commandButton action="{!removeNewObject}" value=" delete " reRender="newItems,panelWithVar" > <!-- -->
<apex:param name="p1" value="{!rowNumber}" assignTo="{!numberOfRowToRemove}"/>
</apex:commandButton>
</apex:column> -->
<apex:column width="5%">
<apex:commandButton action="{!removeNewObject}" value=" edit " reRender="newItems,panelWithVar">
<apex:param name="p1" value="{!rowNumber}" assignTo="{!numberOfRowToRemove}"/>
</apex:commandButton>
</apex:column> -->
<apex:column headervalue="Name" value="{!p.pro.Name}" />
<apex:column headervalue="Code" value="{!p.pro.productcode}" />
<apex:column headervalue="Price" value="{!p.pro.price__c}" />
<apex:column headervalue="Quantity" value="{!p.quantity}"/>
<apex:column headervalue="Total Amount" value="{!p.amount}"/>


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

 

 

 

public with sharing class ProductSearchController
{

public PageReference quicksave() {
return null;
}


/* public String getRowNumber() {
return null;
}*/


public class ProductWrapper {

public Boolean checked{ get; set; }
public Product2 pro { get; set;}
public double quantity{ get; set;}
public double amount{ get; set;}

public ProductWrapper(){
pro = new Product2();
checked = false;
quantity=1;
amount=quantity*pro.price__c;
}

public ProductWrapper(Product2 p){
quantity=1;
pro = p;
checked = false;
amount=quantity*pro.price__c;
}
}
// the results from the search. do not init the results or a blank rows show up initially on page load
public List<ProductWrapper> searchResults {get;set;}
// the categories that were checked/selected.
public List<ProductWrapper> selectedProducts {
get {
if (selectedProducts == null) selectedProducts = new List<productWrapper>();
return selectedProducts;
}
set;
}
// the soql without the order and limit
private String soql {get;set;}
// the collection of products to display
public List<Product2>Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir;
}
set;
}

// the current field to sort by. defaults to name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}

// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}

// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode,price__c from Product2 where name != null';
runQuery();
}

// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}

// runs the actual query
public void runQuery()
{

try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}

}

// runs the search with parameters passed via Javascript
public PageReference runSearch() {
//change
if (searchResults == null) {
searchResults = new List<ProductWrapper>(); // init the list if it is null
} else {
searchResults.clear(); // clear out the current results if they exist
}
//change end
String name = Apexpages.currentPage().getParameters().get('name');
String productcode = Apexpages.currentPage().getParameters().get('productcode');
//String price=Apexpages.currentPage().getParameters().get('price');
soql = 'select name,productcode,price__c from product2 where name != null';
if (!name.equals(''))
soql += ' and name LIKE \''+String.escapeSingleQuotes(name)+'%\'';
if (!productcode.equals(''))
soql += ' and productcode LIKE \''+String.escapeSingleQuotes(productcode)+'%\'';
//if (!price.equals(''))
//soql += ' and price__c LIKE \''+String.escapeSingleQuotes(price)+'%\'';

for(Product2 p : Database.query(soql)) {
// create a new wrapper by passing it the category in the constructor
ProductWrapper pw = new ProductWrapper(p);
// add the wrapper to the results
searchResults.add(pw);
}
// run the query again
runQuery();

return null;
}
public PageReference next() {

// clear out the currently selected categories
selectedProducts.clear();

// add the selected categories to a new List
for (ProductWrapper pw : searchResults) {
if (pw.checked)
selectedProducts.add(new ProductWrapper(pw.pro));
}

// ensure they selected at least one category or show an error message.
if (selectedProducts.size() > 0) {
return Page.Category_Results;
} else {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Product.'));
return null;
}

}
public Integer numberOfRowToRemove { get; set; }
// The method to remove an item from the list
public PageReference removeNewObject(){

selectedproducts.remove(numberOfRowToRemove);

return null;
}

// fired when the back button is clicked
public PageReference back() {
return Page.assignment2;
}
}