3 Replies Latest reply on Sep 28, 2010 4:45 AM by gana

    sorting is not working in the richfaces custom DataTable

    gana

      Hi.

       

      I am trying to implement sorting functionality to my custom dataTable. But the functionlity is not working.

       

      My table header became sortable and even in the fire bug AJAX.Submit() method also invoking when onClick event fires on the table header.

       

      But my table data is not sorting.

       

      Please find my code below.

       

       

       

      for (int i = 1; i <= columns; i++) {
                              header = new HtmlOutputText();
                              header.setValue("header" + i);
                              col = new HtmlColumn();
                              col.setId("col" + i);
                              col.setHeader(header);
                              expression = factory.createValueExpression(elcontext, "#{row[" + (i - 1)+ "]}", String.class);
                              body = new HtmlOutputText();
                              body.setValueExpression("value", expression);
                              col.getChildren().add(body);
                              col.setSortable(true);
                              col.setSortIcon("/webuif/images/ascending.gif");
                              col.setSortIconAscending("/webuif/images/ascending.gif");
                              col.setSortIconDescending("/webuif/images/descending.gif");
                              col.setValueExpression("sortBy",expression);
                              getChildren().add(col);                      

       

      My Bean is like below:

       

      private ListDataModel data;

      public ListDataModel getData() {
              List<String> listdata = new ArrayList<String>(10);
              listdata.add("one");
              listdata.add("two");
              listdata.add("three");
              listdata.add("four");

       

              data = new ListDataModel(listdata);
              return data;
          }

       

       

      Data is properly inserting into my table properly But sorting is not happening.

       

       

      Is there any thing i missed for sorting functionality.

       

      Any help would really appreciated.

       

       

      Br,

      Gana

        • 1. Re: sorting is not working in the richfaces custom DataTable
          kanal

          Refer to http://richfaces-showcase-gae.appspot.com/richfaces/component-sample.jsf?sample=tableSorting&demo=dataTable&skin=deepMarine to see how sorting is implemented in RF 4.x.

           

          Also please read the discussion about dataTables features in richfaces version 4.x

          http://community.jboss.org/thread/156841?tstart=0

          • 2. Re: sorting is not working in the richfaces custom DataTable
            konstantin.mishin

            There is not enough information to help you. When you ask some question, describe your environment, in particular RF version. Post full code of table initialization also.

            • 3. Re: sorting is not working in the richfaces custom DataTable
              gana

              Hi,

               

              Sorry for that. Actually we are developing new webUI framework on top of jsf and richfaces. As part of that we are developing our custom dataTable. So our requirement is that we should implement sorting functionality to our datatable. So In my table user will give EL expression for loading the data and if user specifies sorting is true then my table has to do sorting functionality. So my code looks like this.

               

              for (int i = 1; i <= columns; i++) {

                   HtmlOutputText header = new HtmlOutputText();
                                      header.setValue("header" + i);
                                      col = new HtmlColumn();
                                      col.setId("col" + i);
                                      col.setHeader(header);
                                      expression = factory.createValueExpression(elcontext, "#{row[" + (i - 1)+ "]}", String.class);
                                      body = new HtmlOutputText();
                                      body.setValueExpression("value", expression);
                                      col.getChildren().add(body);
                                      col.setSortable(true);
                                      col.setSortIcon("/webuif/images/ascending.gif");
                                      col.setSortIconAscending("/webuif/images/ascending.gif");
                                      col.setSortIconDescending("/webuif/images/descending.gif");
                                      col.setValueExpression("sortBy",factory.createValueExpression(elcontext, "#{row[" + (i - 1)+ "]}", String.class));
                                      getChildren().add(col);                   

               

                             }

               

               

              So now my table header became sortable and even when i click on the header AJAX.Submit() method also calling when i see in the firebug. But data is not sorting and sorting arrows are also not changing.

               

              Please let me know if any thing required.

               

              Br,

              Gana