0

I tried to integrate a filter in the column "Status" of my Visualforce table. However, I can see the header now, but the table does not return any results for the body. I think it has to do with the declaration of methods and variables.

<apex:page Controller="tableDevRequests">
<apex:form id="form">
    <apex:pageblock >
    <apex:pageMessages />
        <apex:outputpanel rendered="{!editTable==false && generateTask==false && editTask==false}">
            <table class="list" border="0" cellpadding="0" cellspacing="0" id="maintable">
                <thead class="rich-table-thead">
                    <tr class="headerRow">
                        <th class="headerRow">Dev Request Name</th>
                        <th class="headerRow">Status &nbsp;&nbsp;                               
                            <apex:selectList id="searchStatus" value="{!selectedStatus}" size="1">
                                <apex:selectOptions value="{!Status}" id="field"/>
                                <!--<apex:actionSupport event="onclick" reRender="tableData" action="{!getlstDevRequests}"/>-->
                                <apex:actionSupport event="onclick" reRender="tableData" action="{!getlstDevRequests_edit}"/>
                            </apex:selectList>
                        </th>
                        <th class="headerRow">Start Date</th>
                    </tr>
                </thead>
                <apex:outputPanel id="tableData">
                <apex:repeat value="{!lstDevRequests_edit}"  var="item">
                    <tbody>
                        <tr class="dataRow">
                            <td bgcolor="#faffff" height="50">{!item.Name}</td>
                            <td class="statusCol" bgcolor="#faffff" height="50">{!item.Status__c}</td>
                            <td bgcolor="#faffff" height="50"><apex:outputText value="{0,date,MM/dd/yyyy}"> <apex:param value="{!item.Start_Date__c}" /> </apex:outputText></td>
                        </tr>    
                    </tbody>
                </apex:repeat>
                </apex:outputPanel>
            </table>
        </apex:outputpanel>
    </apex:pageblock>           
</apex:form>

</apex:page

Controller:

public with sharing class tableDevRequests {

    public String selectedStatus{get;set;}
    public List<Dev_Request__c> lstDevRequests_edit {get; set;}
    public Task insertnewTask {get;set;}
    public boolean editTable {get;set;}
    public boolean generateTask {get;set;}
    public boolean editTask {get;set;}
    public boolean deleteTask {get;set;}
    public Id selectedItemId { get; set; }


    public tableDevRequests() {
        editTable = false;
        generateTask = false;
        editTask = false;
        lstDevRequests_edit = getlstDevRequests_edit();
        selectedStatus = '-1';
    }

    public List<SelectOption> getStatus() {
              List<SelectOption> statOptions= new List<SelectOption>();
              statOptions.add( new SelectOption('-1','--All Status--'));
              for( Dev_Request__c dev : [select Id,Status__c from Dev_Request__c ] ) {
                      statOptions.add( new SelectOption(dev.Id,dev.Status__c)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/
              }
             return statOptions;
       }

    public List<Dev_Request__c> getlstDevRequests_edit() {

        if(selectedStatus =='-1') {       
            lstDevRequests_edit = [Select Id, Name, Assignee__c, Assignee__r.Name, Start_Date__c, 
            Due_Date_QA__c, Estimated_Hours__c, Estimated_Completion_Date__c, Status__c, 
            Overview__c, Parent_Dev_Request__c, 
            (SELECT Id, WhatId, ActivityDAte, Owner.Name, Description, Status, Subject from Tasks) 
            from Dev_Request__c];
        }
        else {       
            lstDevRequests = [Select Id, Name, Assignee__c, Assignee__r.Name, Start_Date__c, 
            Due_Date_QA__c, Estimated_Hours__c, Estimated_Completion_Date__c, Status__c, 
            Overview__c, Parent_Dev_Request__c, 
            (SELECT Id, WhatId, ActivityDAte, Owner.Name, Description, Status, Subject from Tasks) 
            from Dev_Request__c
            WHERE Status__c =:selectedStatus];
        }        
        return null;
    }
}

As I now have looked into it, it may have to do with the declaration of lstDevRequests_edit, I am not sure if and where to use a getter method and if this collides with the list declaration.

Thank you for your help!

Well, after playing with it further and declaring the initial list in a different method, after changing the status the list appears on top above the table. It seems there is a combination with method and rendering that does not function.

  • You should try to change the action type of your actionsupport to set onchange instead of onclick – Martin Lezer Jan 24 '17 at 7:50
  • Well, thank you, but that is not really the problem here. The problem is the assignment of methods and the rendering. Maybe you have some suggestions on that? – user40501 Jan 24 '17 at 7:59
  • Your <actionsupport> need not to have a action attribute. getlstDevRequests_edit being a getter method will be automatically called on rerender. – Mukesh Verma Jan 24 '17 at 8:05
1

First of all, your repeat on lstDevRequests_edit contains a tbody. The tbody tag doesn't need to be repeated.

Then, your table is linked to the lstDevRequests_edit variable for which you declared a getter and a setter to be accessible from the visualforce page:

public List<Dev_Request__c> lstDevRequests_edit {get; set;}

So in your action support, to filter this list, you only need to call a separate method which updates the list:

public void UpdateLstDevRequests() {

        if(selectedStatus =='-1') {       
            lstDevRequests_edit = [Select Id, Name, Assignee__c, Assignee__r.Name, Start_Date__c, 
            Due_Date_QA__c, Estimated_Hours__c, Estimated_Completion_Date__c, Status__c, 
            Overview__c, Parent_Dev_Request__c, 
            (SELECT Id, WhatId, ActivityDAte, Owner.Name, Description, Status, Subject from Tasks) 
            from Dev_Request__c];
        }
        else {       
            lstDevRequests_edit = [Select Id, Name, Assignee__c, Assignee__r.Name, Start_Date__c, 
            Due_Date_QA__c, Estimated_Hours__c, Estimated_Completion_Date__c, Status__c, 
            Overview__c, Parent_Dev_Request__c, 
            (SELECT Id, WhatId, ActivityDAte, Owner.Name, Description, Status, Subject from Tasks) 
            from Dev_Request__c
            WHERE Status__c =:selectedStatus];
        }        
    }

Then call this method in your action support, which already rerenders the list:

<apex:actionSupport event="onchange" reRender="tableData" action="{!UpdateLstDevRequests}"/>

Finally, you just have to call this method in your constructor to instanciate the list at the beginning with the default values:

public tableDevRequests() {
        editTable = false;
        generateTask = false;
        editTask = false;
        selectedStatus = '-1';
        UpdateLstDevRequests();
    }

EDIT

There's a problem with your instanciation of your status list:

for( Dev_Request__c dev : [select Id,Status__c from Dev_Request__c ] ) {
                      statOptions.add( new SelectOption(dev.Id,dev.Status__c)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/
              }

First of all, you instanciate your list with possible duplicated records. Because I assume Dev_Request__c records can have the same status.

Then, you set as value in your picklist, a Dev_Request__c id. This must be a status like this:

for( Dev_Request__c dev : [select Id,Status__c from Dev_Request__c ] ) {
                          statOptions.add( new SelectOption(dev.Status__c,dev.Status__c)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/
                  }
  • Sorry, no, it is still not working. Still the list then somehow appears on the top of the page and does not rerender. Besides, I cannot change lstDevRequests_edit so easily, as the code is more complex and the list is used in other parts of the code. – user40501 Jan 24 '17 at 8:21
  • Ok, to be more specific, the initial screen loads nicely with the previous controller method, meaning leaving lstDevRequests_edit = getlstDevRequests_edit(); in and leaving UpdateLstDevRequests(); out. – user40501 Jan 24 '17 at 8:23
  • When I now change the status, for "All Status" the list appears on top of the page, but for the other status there is no body at all. – user40501 Jan 24 '17 at 8:24
  • Ok I missed something. Whay are you filling the status list by selecting Dev_Request? That means that you can have multiple times the same status in the picklist. – Martin Lezer Jan 24 '17 at 8:30
  • Ah yes, you are right. Ok, so what I do now is the following: – user40501 Jan 24 '17 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.