Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Dynamic Row Selection
posted

I want to highlight some of the rows of GridView depending on certain condition.

For eg.

If a web grid contains 3 colums Emp id, Emp Name and Salary then I want to highlight those rows with Red color whose salary is greater than some value say 10000.

Can I know how to implement this using web grid?

Parents
No Data
Reply
  • 1765
    posted

    Hi drumilbhattad, Row background color could be set in serverside as well. Please follow below steps.

     

    Thank you!

    Swetha

     

    1) In JSP: Bind all the <ig:column> 'style' attribute to bean as shown below.

    <ig:gridView

        dataSource="#{webGridRowStyleBean.dataList}"

        id="grid">   

          <ig:column style="#{DATA_ROW.basicBg}">

            <f:facet name="header">

                <h:outputText value="First Name" />

            </f:facet>

            <h:outputText value="#{DATA_ROW.firstName}" />       

        </ig:column>

    </ig:gridView>

     

    2) Backing Bean: In getDataList() method check if salary is >=10000 and set ‘background-color’

     

    private List getDataSource() throws Exception{

                dataSource = new ArrayList();

               

                PersonInfo personInfo = new PersonInfo("Boyle", "Allene", 8000 , "768-4994");

                dataSource.add(personInfo);        

                personInfo = new PersonInfo("Rolfson", "Karine", 12000 , "663-6448");

                dataSource.add(personInfo);        

                personInfo = new PersonInfo("Roberts", "Blaise", 9000 , "037-9519");

                dataSource.add(personInfo);        

                personInfo = new PersonInfo("Okuneva", "Anaya", 15000 , "695-8691");

                dataSource.add(personInfo);        

                personInfo = new PersonInfo("Ken", "Steve", 10000 , "147-2589");

                dataSource.add(personInfo);

     

                return dataSource;

          }

         

          public List getDataList() throws Exception{

                List list = getDataSource();       

                Iterator iterate = list.iterator();

                while(iterate.hasNext()){

                      PersonInfo personObj = (PersonInfo) iterate.next();

                      if(personObj.getSalary() >= 10000){

                            personObj.setBasicBg("background-color: red");

                      }                

                }

               

                return list;     

          }

     

Children
No Data