7 Replies Latest reply on Oct 22, 2010 9:01 AM by liumin hu

    a question about  datatable sorting / filtering

    liumin hu Master

      hi,

       

      I want to know how can i get the sorting/filtering result of datatable. Does the sorting change the order of the backing bean's list property?

       

      thanks in advance

       

      liu

        • 1. Re: a question about  datatable sorting / filtering
          Akaine Harga Novice

          As far as I know the filtering and sorting is done on client-side level using JS thus the backing property remains unchanged. And I'm not aware of any mechanism to inject the filtered data into the backing bean.

           

          If it's really necessary to achieve this functionality the only thing that comes to mind is to "filter" and rebuild manually the list property on Java level and rerender the datatable each time. This way if you use an XLS or PDF exporter the data will be exported exactly as the user sees it.

          • 2. Re: a question about  datatable sorting / filtering
            liumin hu Master

            hi,

             

            thanks for your reply. it is bad to hear that. my client want to print the data on the screen. the filtering/sorting event sends a ajax request everytime, i thought it change the data model too.

             

            if i want to resort/refilter the list manually, how can i get the filter string or the column to sort. or you means i should do it myself.

             

             

            liu

            • 3. Re: a question about  datatable sorting / filtering
              Ilya Shaikovsky Master

              Hi Guys!

               

              at first - the statement that sorting and filtering done at client level - is not valid. We have no such client side functionality at all. (planned to some of 4.x versions)

               

              But in the same moment - yes, if you passing to dataTable just the list - it does not make changes according to these operations. The reasons is simple. UI component - can't be responsible for model changes. It's completelly unexpected for me that some data mapped to DB will be changed because of UI representation changes. JSF components - should not directly operate with data or it will not works according to MVC pattern. If you implementing your modal on your own and passing to dataTAble - you getting full access on the filtering and sorting operations in modify model method.

               

              So the only way - to call walk method on the model(getting it from component object). the you will also be able to output data according to all the sorting/filtering applied. I had already finished such sample of export to Excel but lost the code during revert by mistake but I'm still planning to done it in nearest time https://jira.jboss.org/browse/RFPL-462

              • 4. Re: a question about  datatable sorting / filtering
                liumin hu Master

                hi,

                 

                Ilya Shaikovsky wrote:

                 

                If you implementing your modal on your own and passing to dataTAble - you getting full access on the filtering and sorting operations in modify model method.

                 

                do you mean binding a htmldatatable to rich:datatable, or use a listdatamodel for the value of datatable. or something else?

                 

                hope see your code example soon.

                 

                thanks

                 

                liu

                • 5. Re: a question about  datatable sorting / filtering
                  Akaine Harga Novice

                  Ilya Shaikovsky wrote:

                   

                  at first - the statement that sorting and filtering done at client level  - is not valid. We have no such client side functionality at all.

                   

                  Din't know that, was just guessing ("As far as I know...") xD

                  • 6. Re: a question about  datatable sorting / filtering
                    Nick Belaevski Master

                    You should implement Modifiable/extend ModifiableModel and pass it as table component value. In the "modify" method you'll get filter/sorting information passed.

                    • 7. Re: a question about  datatable sorting / filtering
                      liumin hu Master

                      hi

                      I followed nick's suggestion.here is my code.

                      public class MyDataModel extends ModifiableModel {
                      
                              public MyDataModel(List<?> _list){
                                  super(new ListSequenceDataModel(_list),"dos");
                              }
                             
                              List<Object> getRowKeys(){
                                  return this.rowKeys;
                              }
                          }
                      

                       

                      what i dont like is I have to hard-code var parameter of the datatable, Is there another way to do this? what i need is just get the filter result like the post mentioned in ilya's jira.

                       

                      any other suggestion?

                       

                      thanks in advance

                       

                      liu