3 Replies Latest reply on Oct 10, 2006 8:04 AM by jlingwai

    DataGrid Sorting

    jlingwai
      hey,
      Senerio:
      I have a datagrid and I have sorting enabled. Now within the datagrid I have a total row. When I sort the datagrids by columns the total line is not always the first row.... Is it possible to locate the total row and place it in the first row?

      I've tried creating a new ArrayCollection and using the addItemAt() but i get an error saying when sorting the addItemAt() is meaningless? Any Ideas?

      -JoSh
        • 1. Re: DataGrid Sorting
          peterent Level 2
          An idea I had is to create a new Collection class by extending ArrayCollection. The new class does basically everything ArrayCollection does but keeps the totals separate from the data. Without actually planning it out I don't know if it is a good idea, but I think it is worth exploring.
          • 2. Re: DataGrid Sorting
            peterent Level 2
            I think I have a better idea. I think you've already added a row to your data to hold the totals. Make that row unique in some way, such as adding a field called "totals" and setting it to 1 or true or something. Don't add it to the other rows.

            You will need to write your own Sort compareFunction, but when you do, check to see if either item has the totals field set and if so, return -1 (or 1) so that it always sorts first. Then no matter what values are in your data, the totals row will always be at the top.

            This should be easier than extending ArrayCollection.
            • 3. Re: DataGrid Sorting
              jlingwai Level 1
              Thanks,
              Your second Idea i think will be the best in this situation. considering the following, I have the datagrid formatted with "%" and "$" so it sorts the columns as strings and not numbers. So I have to write a new Sort compareFunction anyways to get the columns to sort properly. Currently it sorts 0-9 and does not compare the actual value, hence, this list of numbers(100, 98, 500, 60, 12) would be sorted like (100, 12, 500, 60, 98) and not (500,100,98,60,12).