3 Replies Latest reply on Oct 8, 2008 4:21 AM by Michael Glock

    Exporting a sorted (!) datatable to PDF

    Michael Glock Newbie

      Hello,

      I use a rich:datatable which must be sortable and whose contents must be exportable to a PDF file. The table consists of three columns, two of them being auto-sorted and one that uses external sorting.

      Externally sorting the table (via comparator) is working but apparantly the list saved in session scope remains untouched. When I press the button for exporting the list, the result is that the PDF file contains the unsorted list which is unwanted behaviour.

      I managed to save the sorting direction in my compare method so that I can access it from my managed bean just before creating the PDF file and sorting again. However, I didn't find a way to figure out which column was sorted.

      I really don't know how to achieve this requirement so any ideas and tips are welcome and appreciated. Thanks.

      Regards

        • 1. Re: Exporting a sorted (!) datatable to PDF
          Alexander Parij Newbie

          Well , for me even out of the box alphabetical sorting is not working ( (but auto-sorting is working).
          Did you manage to make it sorted while you press the "sort arrow" ?

          If you familiar with "Charles" very helpfull tool to debug your http session. From what I saw the list in session in never sorted , but the response to the AJAX request should contain the sorted table.

          Hope it helps somehow....

          • 2. Re: Exporting a sorted (!) datatable to PDF
            Michael Glock Newbie

            Hi aparij,

            thanks for your response.

            I am not quite sure what you mean by "out of the box" sorting vs. auto-sorting. For me, something like

            <rich:column sortBy="#{Item.change}" sortable="true" selfSorted="true">


            (where "change" is a String property) is working fine and is correctly sorted in alphabetical order when pressing the sorting arrow. I suppose that is what you mean by out of the box sorting?

            I agree with your assumption that the list in session never really gets sorted. The compare method in my comparator just compares all objects from that list to each other so the result is just temporary:

            public int compare(LogItem o1, LogItem o2)
             {
             int ret = 0;
            
             if (ordering == Ordering.ASCENDING)
             {
             if (o1.getDate().after(o2.getDate()))
             ret = -1;
             else if (o2.getDate().after(o1.getDate()))
             ret = 1;
             }
             else
             {
             if (o2.getDate().after(o1.getDate()))
             ret = -1;
             else if (o1.getDate().after(o2.getDate()))
             ret = 1;
             }
            
             return ret;
             }


            So I don't know if there is a sorted list in a HTTP response in some way. But if there is, how can I access that list from that response?


            • 3. Re: Exporting a sorted (!) datatable to PDF
              Michael Glock Newbie

              Oh, and thanks for your recommendation "Charles". Never heard of it before...