A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Sort method and multidimensional array

  1. #1
    Junior Member
    Join Date
    May 2000
    Posts
    26
    I'm pulling data from a database into a 2d array (5000 rows, 20 columns), for the data to be analyzed from my Flash page. The user may want to display only rows containing certain data and sort the data by one of many columns.

    I'm trying to figure how I could take advantage of the sort method to do this. The trick is that once a column is sorted, I would want all columns moved around according to the sort order of that column.

    Have any of you experimented with this type of data grid? Any suggestions or warnings?

    Thanks,

    Gary

  2. #2
    Junior Member
    Join Date
    Sep 2000
    Posts
    26
    let me try and help even a bit: i have not played too mch withthat many elements in a flash array and sorting it, but, i would imagine that if the values are being pulled from a database back-end, it might be better to just reload the variables from the server as it most likely has sorting routines built into the database that keep all the columns in order and stuff... there may not be a need to do it in flash...

    hope this helps

  3. #3
    not your average sock puppet finnegan's Avatar
    Join Date
    Dec 2000
    Posts
    53
    If you are using SQL to access the database, do the sort at the database read stage by using the 'ORDER BY..." phrase in your SQL statement.

    This is way more efficient than using actionscript to sort an array.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Posts
    2,235
    If you make the arrays multidimensional with rows and columns;

    row1 = new Array(co1,co2,co3);

    where cols are themselves arrays. You can then access each sub element with row1[n][m]

    e.g.

    if col 2 = ("a","b","c")


    row1[1][2] = "c";

    you can then sort the row and the columns will be in the right place...


    ~mgb

  5. #5
    Junior Member
    Join Date
    May 2000
    Posts
    26
    Thanks michelangelo, finnegan, and mgb for the replies and suggestions.

    Just to clarify, michelangelo, and finnegan, are you both saying that it would be faster to go back out to the server and have SQL Server retrieve/sort the values than to simply sort the values that are already resident in memory? I know how to do that, but it just seems that on a table that is only 5000 rows long, it would be far more efficient to just sort in memory. I'm probably missing some aspect here though.

    And mgb, what you are saying is exactly how I'm loading things (2d array). What I'm struggling with is how to specify the 2nd diminsion on the sort method. In other words, when I want to sort the entire grid by the 3rd column, and have all rows ordered by that column, I'm having trouble with the syntax for the sort method. Haven't seen any examples of its use in this way, so it may not be possible, and I may have to write my own sort.

    Thanks again to each of you for taking the time to help,

    Gary

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Posts
    2,235
    ok, I haven't dealt with arrays this larget but this should work;

    for(j=1;j<5001;++j){
    for(k=0;k<21;++k){
    row[j] = new Array();
    row[j][k]=col[j];
    row[j].sort();
    row[j][k].sort();
    }

    // this should create and sort the row and col arrays but you will have to load them with the right numbers and so on. Try it on a small scale first...

    ~mgb


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center