Subscribe Bookmark RSS Feed

Sorting a Table Box in JMP 11

I've run into a little scripting problem, and enclose below a small demo script I’ve created to illustrate it. What I want to do is to write a list of ranks (i.e. put 1 in the first row, 2 in the second and so on) into the first column of a Table Box that I have just sorted in any of several different ways.

If I run the following script, sort by any column using the radio buttons provided, and then click on either the "Insert Rank" or the "Clear Rank" button, I find that the Table Box reverts to its original unsorted order before the new values are written.  I want to prevent it from doing that.  Does anyone have any ideas, please?   I can think of one possibility that would involve copying every column into a second Table Box before adding the ranks, but that's rather convoluted, and I feel this ought to be a very easy thing to do.

(This demo only works in JMP 11, as the sorting of Table Boxes in this way has only just become available in this release.)

dt = Open( "$SAMPLE_DATA/Fitness.jmp" );

nr = N Row( dt );

myTableBox = Table Box(

       Number Col Box( "Rank", Repeat( ., nr ) ),

       String Col Box( "Name", (Column( dt, "Name" ) << get values) ),

       String Col Box( "Sex", (Column( dt, "Sex" ) << get values) ),

       Number Col Box( "Age", (Column( dt, "Age" ) << get values) ),

       Number Col Box( "Weight", (Column( dt, "Weight" ) << get values), << set format( 6, 1 ) ),

       <<table style( "Heading Separator" )

);

Close( dt, nosave );

myTableBox << set shade alternate rows( 1 );

expr_Sort = Expr(

       Choose( myRadioBox << get,

              myTableBox<< sort by column( 1, 1 ),

              myTableBox<< sort by column( 2, 1 ),

              myTableBox<< sort by column( 3, 1 ),

              myTableBox<< sort by column( 4, 0 ),

              myTableBox<< sort by column( 5, 0 ),

       )

);

myRadioBox = Radio Box( {"Sort by Rank", "Sort by Name", "Sort by Sex", "Sort by Age", "Sort by Weight"}, expr_Sort );

myWindow = New Window( "My Window",

       H List Box(

              Lineup Box( N Col( 1 ),

                     Panel Box( "Sorting Options", myRadioBox ),

                     Button Box( "Insert Rank", myTableBox[1] << set values( Index( 1, nr ) ) ),

                     Button Box( "Clear Rank", myTableBox[1] << set values( Repeat( ., nr ) ) ),

              ),

              Text Box( "   " ),

              Panel Box( "Data", myTableBox )

       )

);