You need to sign in to do that
Don't have an account?
james7630
VF Page to use date field to filter query for datatable
I want to have a date field on a page above my datatable where I can click a date and that date is then used in the query that populates the datatable objects. I have the date field and the datatable but cant seem to get them working together. I can populate the datatable on intial load by hard coding date,today for the query.
public class RenewalController { public RenewalController(ApexPages.StandardController controller) { } public String getDate() { return selectedAccount; } public String selectedAccount { get; set; } public List<Entities__c> myents = new List<Entities__c>(); public List<Entities__c> getMyList() { date dt; if(getDate()!= null) dt = Date.parse(getDate()); else dt = date.Today(); integer mo = dt.month(); myents = [select id,Packet_Sent__c,Stamped_List_Received_from_State__c,Renewal_Emailed__c ,List_Filed_with_State__c,Received_Payment_For_Renewal__c,Renewal_Received_From_State__c ,State_Renewal__c,Renewal_Printed__c, Primary_Client__c, Name from Entities__c where (CALENDAR_MONTH(State_Renewal__c) =: mo)]; return myents; } }
page
<apex:page standardController="Entities__c" extensions="RenewalController" tabStyle="Entities__c" sidebar="false"> <apex:form > <input id="datefield1" name="datefield1" onfocus="DatePicker.pickDate(false, 'datefield1', false);" size="12" type="text" value=""> <apex:param name="id" value="{!Date}" assignTo="{!selectedAccount}"/> </input> <apex:pageBlock title="Entity" mode="edit" id="ent"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}" rerender="ents" status="ajaxStatus"/> <apex:commandButton action="{!cancel}" value="Cancel"/> <apex:commandButton value="AutoFillDate" action="{!AutoFill}" rerender="ents" status="ajaxStatus"/> </apex:pageBlockButtons> <apex:dataTable value="{!myList}" var="opp" id="ents"> <apex:actionSupport event="onchange" rerender="ent" status="status"/> <apex:column headerValue="Entity">{!opp.Name} </apex:column> <apex:column headerValue="Renewal Due Date"> <apex:inputField value="{!opp.State_Renewal__c}" id="renew"/> </apex:column> <apex:column headerValue="Renewal Received"> <apex:inputField value="{!opp.Renewal_Received_From_State__c}"/> </apex:column> <apex:column headerValue="Printed Renewal"> <apex:inputField value="{!opp.Renewal_Printed__c}" id="print"/> </apex:column> <apex:column headerValue="Emailed Renewal"> <apex:inputField value="{!opp.Renewal_Emailed__c}"/> </apex:column> <apex:column headerValue="Rec Pay For Renewal"> <apex:inputField value="{!opp.Received_Payment_For_Renewal__c}"/> </apex:column> <apex:column headerValue="List Filed With State"> <apex:inputField value="{!opp.List_Filed_with_State__c}"/> </apex:column> <apex:column headerValue="Stamped List Received"> <apex:inputField value="{!opp.Stamped_List_Received_from_State__c}"/> </apex:column> <apex:column headerValue="Packet Sent"> <apex:inputField value="{!opp.Packet_Sent__c}"/> </apex:column> </apex:dataTable> <script> function CopyShipInfo() { document.getElementById('{!$Component.ents.renew}').value = document.getElementById('datefield1').value; </script> </apex:pageBlock> </apex:form> </apex:page>
solution I found on bobs page, great stuff...
http://bobbuzzard.blogspot.co.uk/2011/07/passing-parameters-to-apex-method-from.html
All Answers
HI
The following query works because the date field, CloseDate, is in the GROUP BY clause. This wouldn't work for a dateTime field, such as CreatedDate.
In your query use group by or order by clause.
check this link how to use calender_month():-
http://blogs.developerforce.com/tech-pubs/2011/12/calculation-fields-in-summary-soql-queries.html
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_date_functions.htm
Thanks, but thats not my issue. My issue is that I cant get that variable for the date field from the page to the controller and into the query to rerender the datatable. I just want to be able to select a date on the page and that will cause the datatable to rerender and give me a datatable with just those objects within that date range.
Thanks in advance..
The way that you are sending the selected value to the controller looks wrong to me:
I can't see how the apex:param will help here, as its not nested in a visualforce component.
Take a look at this blog post of mine regarding custom date pickers - http://bobbuzzard.blogspot.co.uk/2012/03/custom-date-picker.html - that has some sample code that shows how to bind to a controller property.
Hi Bob,
Thanks for the reply, I think I found something on one of your other posts about rerendering but now it isnt showing up at all.
I added a nested Output panel and I am trying to render the inner and rerender the outer container but nothing shows up, can you see any errors in the page or controller? I am using the autofill button to initiate the update after i fill in a date. Thanks again..
solution I found on bobs page, great stuff...
http://bobbuzzard.blogspot.co.uk/2011/07/passing-parameters-to-apex-method-from.html