14 Replies Latest reply on Jun 6, 2007 6:22 AM by Gboro54

    sorting columns

      Hey...I figured out the answer from the last post i left but i need help with one more thing....I have a function that allows multicolumn sorting by basing strings to a database as sql statements...My question is though i want the arrows at the top of each column the user has clicked to stay indicating the way the column is sorted...Any suggestions on how to do this???
        • 1. Re: sorting columns
          You can use the headerRelease event to keep track of how the user has sorted the columns.
          • 2. Re: sorting columns
            Gboro54 Level 1
            how would i have an arrow stay in next to the name of the column...should i draw my own arrow and load it??? or is there a way to allow that arrow to stay there
            • 3. Re: sorting columns
              Gboro54 Level 1
              alright i am not going to lie, i am not sure where to go with this...my resortColumn method is run on the headerRelease...but i am not sure how to have the arrows display....What happens is that the user holds ctrl if he wants to sort by multi columns and when he realeases control the database is requeyed passing a sql statement to the database with the name of the columns and the direction....i want the arrows to display when the user clicks and after the database is requiered...
              • 4. Re: sorting columns
                Gboro54 Level 1
                any suggestions for this???
                • 5. Re: sorting columns
                  JabbyPandaUA Level 3
                  You'd better provide some source code, because I find it difficult to understand what is your question is.
                  • 6. Re: sorting columns
                    Gboro54 Level 1
                    Ok, that is not problem...i can explain the code maybe a little better...What i have is a function called resortColumns(dge:DataGridEvent), which gets called by the datagrid with the headerRealease....What this function does is check to see if the ctrl key is being held or not...If its held it will attach the name of the column and the direction it is to be sorted in(ASC or DESC) to a string then when the ctrl is relased it sends the string as a SQL statement to the server and displays the columns that were selected sorted....If the ctrl key was not held down then it just sends the column name and direction as a SQL statement and the column is resorted....what i want is for the arrows in the header to always stay displayed when the column was selected to be sorted by...
                    • 7. Re: sorting columns
                      JabbyPandaUA Level 3
                      Thanks for clarification, I guess now I had understood your question.

                      You can wait for Flex 3 which will inlclude Advanced DataGrid with support for multiple sorting;)

                      Ok, a hint - you should not never be afraid to gain the knowledge of innerworkings of Flex 2 SDK UI components by opening source files

                      inside Datagrid.as you can find protected method placeSortArrow() that draws an arrow in a header.

                      By extending Datagrid with your own component, you will get an access to this method and can call it in your resortColumns function to draw an arrow where expected.

                      • 8. Re: sorting columns
                        Gboro54 Level 1
                        how to i open Datagrid.as ...i am not even sure where it is, other wise i would have opened it,lol...thanks for the help
                        • 9. Re: sorting columns
                          Gboro54 Level 1
                          ok, i fould the datagrid.as....any suggestions on functions to override(i figured placeSortArrow needs to but anything else)...and any suggestions on how to do this??? Thanks again for the help
                          • 10. Re: sorting columns
                            dimival Level 1
                            I am assuming you are not using the default DataGrid, are you? Because if you are using it then the arrows should always appear, it is like the normal behavior of the DataGrid.

                            So assuming you are not using a normal DataGrid, then you would need to do your own class that extends from DataGrid and implement all the extra functionality that you want. I don't think you need to override the placeSortArrow( ) method, i think that you will need to include your resortColumns( ) method in you own DataGrid subclass and have it call the placeSortArrow( ) whenever you need it.
                            • 11. Re: sorting columns
                              Gboro54 Level 1
                              hmmm interesting, i never thought about doing it that way....would i want to just add a resortColumns()method and just leave everything else alone???
                              • 12. Re: sorting columns
                                dimival Level 1
                                Yes, that's the whole idea of extending a class, you get all the super class methods, and you can add your own without messing up with the normal and default behavior
                                • 13. Re: sorting columns
                                  JabbyPandaUA Level 3
                                  True, I agree with dimival.

                                  But it is not a trivial task in that particular case to reuse in you code protected method placeSortArrow().

                                  It is kind of pain and many people who went this road were are not very happy!

                                  http://www.mail-archive.com/search?l=flexcoders%40yahoogroups.com&q=placeSortArrow&sourcei d=Mozilla-search

                                  • 14. Re: sorting columns
                                    Gboro54 Level 1
                                    Thanks for all your help...You guys have really helped my gain a better understanding of flex(i have only been using it for a little over a month)...Thanks for all the help