cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
acfbt
Level I

How do I select all colored cells in a data table

A data table was given to me where certain rows are colored red to indicate issues, but I do not know the logic behind the issues. How do I go about selecting all rows colored red in JSL?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: How do I select all colored cells in a data table

As Jim stated, cell coloring can be related to or independent of row colors.  The only way I know how to get to Cell Colors for a specific column is to get the column script and "unpack" the expression (script)  arguments.

 

If a columns contains colored cells, it has an argument Color Cells( {... } ) where the list contains one or more lists, the first item in each list is the color number and the second item in the list is another list, a list of cells(rows) with that color.  The 2 item list format is called a name-value pair. The attached script does not handle the case where the cell color is not an integer.

 

I wish JMP would make Color Cells a Column Property so col << get Column Property("Cell Colors") would return the list, without searching for the argument.  

 

Jim might have a simpler solution. Attached is the table Cars_modified.jmp and a script that uses it.  The script references the table from c:/temp, so modify the script to have the correct table path.

 

 

 

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How do I select all colored cells in a data table

There is not a direct way to get this.  Partly because the issue is, are the rows colored, or are the cells colored.  To determine this, if you look in the column that has the row number in it, that is, look in the Row State Column, and if there is a marker in the the rows where the rows are colored, and it is the same color as the row, then the rows are colored.  If in a row which is colored, there is no colored marker in the Row State Column, the each cell is colored.

 

Which of these is the case for you?

Jim
gzmorgan0
Super User (Alumni)

Re: How do I select all colored cells in a data table

As Jim stated, cell coloring can be related to or independent of row colors.  The only way I know how to get to Cell Colors for a specific column is to get the column script and "unpack" the expression (script)  arguments.

 

If a columns contains colored cells, it has an argument Color Cells( {... } ) where the list contains one or more lists, the first item in each list is the color number and the second item in the list is another list, a list of cells(rows) with that color.  The 2 item list format is called a name-value pair. The attached script does not handle the case where the cell color is not an integer.

 

I wish JMP would make Color Cells a Column Property so col << get Column Property("Cell Colors") would return the list, without searching for the argument.  

 

Jim might have a simpler solution. Attached is the table Cars_modified.jmp and a script that uses it.  The script references the table from c:/temp, so modify the script to have the correct table path.

 

 

 

dn610
Level III

Re: How do I select all colored cells in a data table

dt = Open("C:/temp/Cars_modified.jmp");
//______________________________________________________________________________________

//A function to find the colored cells in a specific column.
//-15341335 = reddish color, 73 = yellowish, 36=greenish  
get_colored_cells = Function( {col}, {_s,i, xp, clr_aa=0 },
   // If IsMissing(clr) then get all colors
	_s = col << get script ; 
	for(i=1, i<=narg(_s) , i++,
        xp = Arg(_s, i);
        if(Head Name(xp) =="Color Cells", 
   //this only works if the color is an integer might need a for loop to change the 
   //key to the RGB value
            clr_aa = Associative Array(Arg(xp,1));  
            clr_aa << set default value(0);
            Break()
        ); 
    );
   clr_aa 
);
//_______________________________________________________________________________________

// Usage examples:
model_aa = get_colored_cells( Column("Model"));
dt<< select rows (model_aa[73]);

I modified the above example to select yellowish cells, and it worked when there are multiple colors in the "Model" column. When there's only 1 color in the column, it doesn't work. How can I modify the script so that colored cells within the Model column can be selected when there's only 1 color that's used in the column?

 

 

acfbt
Level I

Re: How do I select all colored cells in a data table

In this case the rows are colored and not individual cells.

txnelson
Super User

Re: How do I select all colored cells in a data table

Then you want to use the following code(modified from @gzmorgan0 code)

//get and table row with a specified color
_colorRows = dt << get rows where (Color Of( Row State( Row() ) ) != 0) ;

dt<<select rows(_colorrows);
Jim