You need to sign in to do that
Don't have an account?
1542VeMan
Need help with ActionFunction call using a table variable as the parameter
I am using a wrapper class to combine an sObject with a checkbox, then iterating over the wrappers in my list. The first column displays the checkbox, then a repeat tag iterates over a list of strings derived from the object fieldNames, allowing the table to render columns according to the object's fieldSet.
the 'fieldSetList' is a list of field Names and I'm using a dynamic APEX process so that the client can reconfigure their table by changing the value and their order in the field set on the custom object.
The table displays correctly, however I want to be able to sort the table by clicking on the column. To do this, I have tried to add an onclick call to an ActionFunction ('sortCLTable') to the column and sending the repeat tag's interation variable ('f') as a parameter: 'onclick="sortCLTable(f)"'
The ActionFunction's parameter should set the sortValue property in the controller, and run the sorttable method, but alas it does not. The table columns have no response whatsoever.
Although the 'f' is working to set the column header and reference the correct field value. it doesn't appear to be passing through the onclick call as a parameter to the apex:Param value associated with the function, or to the controller's corresponding 'sortValue' property. I think I've written the page tags correctly...
Using ActionSupport instead appears to mess up the repeat function such that the column names no longer appear - not sure why. Neither do the columns sort.
I can add more code from my example if needed, but figured this would describe the problem. Any help is much appreciated.
Thanks
the 'fieldSetList' is a list of field Names and I'm using a dynamic APEX process so that the client can reconfigure their table by changing the value and their order in the field set on the custom object.
The table displays correctly, however I want to be able to sort the table by clicking on the column. To do this, I have tried to add an onclick call to an ActionFunction ('sortCLTable') to the column and sending the repeat tag's interation variable ('f') as a parameter: 'onclick="sortCLTable(f)"'
The ActionFunction's parameter should set the sortValue property in the controller, and run the sorttable method, but alas it does not. The table columns have no response whatsoever.
<apex:page ...> <apex:form> <apex:outputPanel id="thePanel"> <apex:pageBlockTable value="{!CLWraps}" var="CLWrap"> <apex:column headervalue="Select" > <apex:inputCheckbox value="{!CLWrap.selectbox}"/> </apex:column> <apex:repeat value="{!fieldSetList}" var="f" > <apex:column value="{!CWrap.CL[f]}" onclick="sortCLTable(f)"/> // I've also tried sortTable('f'), sortCLTable({!f}) and sortTable('{!f}') </apex:repeat> </apex:pageBlockTable> </apex:outputPanel> <apex:actionFunction action="{!sortTable}" name="sortCLTable" reRender="thePanel"> <apex:param name="firstParam" assignTo="{!sortValue}" value="" /> </apex:actionFunction> </apex:form> </apex:page> CONTROLLER contains: public string sortValue {get; set;} public pageReference sortTable(){ resetQueryWithSortValue(sortValue); return null; }
Although the 'f' is working to set the column header and reference the correct field value. it doesn't appear to be passing through the onclick call as a parameter to the apex:Param value associated with the function, or to the controller's corresponding 'sortValue' property. I think I've written the page tags correctly...
Using ActionSupport instead appears to mess up the repeat function such that the column names no longer appear - not sure why. Neither do the columns sort.
I can add more code from my example if needed, but figured this would describe the problem. Any help is much appreciated.
Thanks
When I use the 'f' variable in a Visualforce reference with {!}, the variable renders correctly as the string. For example, I can use this to get the header value:
However, I can't use the f value as a parameter to the sortTable function - none of these work: onclick="sortCLTable(f)", onclick="sortCLTable('f')",onclick="sortCLTable({!f})", onclick="sortCLTable('{!f}')"
So, what's the best way to get the table variable to render as the string it represents into the Javascript function calls,
This saves, and the columns and field values render, but still the columns on the rendered table are inert. I've removed the need to call a specific Javascript function, and I would think that the value attribute in the apex:param should be going through, but since the column is still not live no value is getting sent to the controller - actually nothing is happening so there is no debug log to check.
I can't help but feel I'm missing something obvious...
to
see what happens?
<apex:column value="{!CWrap.CL[f]}" onclick="sortCLTable(\"{!f}\")"/> caused complaints about not finding the column's end tag (/>).
I found a way to get the sorting function to work using an ActionSupport, but its not obvious. Unfortunately, I still don't have an answer to the question about the actionFunction not being called by the onclick attribute on the column, or the provided parameter not being set in the controller property. I should say that I'm looking to use an apex:repeat variable attribute rather than a table variable, but I haven't seen any suggestion that this would be the issue.
I hope to be able to understand the actionFunction and its limitations in situations like these when one is unable to find the correct syntax to add a variable value into the apex:param value attribute used in an actionFunction's action method, when called from another component's onclick event.
Its like you have to take a value understandable in Visualforce, convert into something a javascript method call can understand, then reconvert it back to a Visualforce param attribute value. Is this a situation where Visualforce remoting is required??
Would love for someone to suggest the right solution, but thanks @jp1234 for your kind assistance!!
Anyway, the solution to my problem (although not the answer to my question) is to use the actionSupport tag. If the question were about how to get the columns of a table to sort, this would be a good answer:
http://www.sundoginteractive.com/sunblog/posts/a-recipe-for-column-sorting-salesforce-visualforce-page
http://bobbuzzard.blogspot.ca/2014/09/sorting-visualforce-tables-with.html