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

    sorting is not working in the richfaces custom DataTable

    Gana Prasad Newbie

      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

        • 2. Re: sorting is not working in the richfaces custom DataTable
          Konstantin Mishin Novice

          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 Prasad Newbie

            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