<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic MakeRowStateHandler function: Exclude and Hide all but selected rows over different data table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789423#M96993</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to handle several Data Table and I would like to use only one filter. Ideally I would like to hide and exclude all the data that are not selected over different data table.&lt;/P&gt;&lt;P&gt;I used a modified version of a JSL code made my ian.cox@jmp.com, see below on JMP 17.0.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// ian.cox@jmp.com: 03Nove2014

// Demo of how to link multiple child tables to a parent table using a row state handler

Names Default To Here( 1 );

// Make some tables to use

dt1 = New Table( "Table 1",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Values( (1 :: 10)` ) ),&amp;nbsp;
New Column( "Response", Numeric, Continuous, Formula( Random Normal( 0, 1 ) ) )
);
dt1 &amp;lt;&amp;lt; Set Name ("dt1 Master");

dt2 = New Table( "Table 2",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 5 ) ) ),&amp;nbsp;
New Column( "Attribute 2", Numeric, Continuous, Formula( Random Integer( 0, 10 ) ) ),&amp;nbsp;
AddRows( 20 )
);
dt2 &amp;lt;&amp;lt; Set Name("dt2 - slave");

dt3 = New Table( "Table 3",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 11 ) ) ),&amp;nbsp;
New Column( "Attribute 3", Numeric, Continuous, Formula( Random Integer( 0, 100 ) ) ),&amp;nbsp;
AddRows( 30 )
);
dt3 &amp;lt;&amp;lt; Set Name("dt3 - slave");
// Utility function:
// Given a data table, a column therein and some value(s) in that column, selects all corresponding rows.
// Need to allow for 'col' to be numeric (character), in which case 'vals' is a matrix (is a list).

selectMatchingRows =&amp;nbsp;

Function( {dt, col, vals},&amp;nbsp;
rows2select = [];
If( Is Matrix( vals ),&amp;nbsp;
&amp;nbsp; // 'col' is numeric
For( i = 1, i &amp;lt;= N Row( vals ), i++,&amp;nbsp;
rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) );
)
,&amp;nbsp;
&amp;nbsp; // 'col' is character
For( i = 1, i &amp;lt;= N Items( vals ), i++,&amp;nbsp;
rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) );
)
);

dt &amp;lt;&amp;lt; Select Rows( rows2select ) &amp;lt;&amp;lt; Hide &amp;lt;&amp;lt; Exclude;
/*
dt &amp;lt;&amp;lt; Exclude;
dt &amp;lt;&amp;lt; Hide;
*/
);

// Make a row state handler to be assigned to the 'master' table (dt1). Allow for multiple row selections.

propagateSelectionToOtherTables =&amp;nbsp;
Function( {x},&amp;nbsp;
&amp;nbsp; // Get the rows that have been selected
selectedRows = dt1 &amp;lt;&amp;lt; GetSelectedRows;
If( N Row( selectedRows ) &amp;gt; 0,&amp;nbsp;
&amp;nbsp; // Clear any existing selection
dt2 &amp;lt;&amp;lt; ClearSelect;
dt3 &amp;lt;&amp;lt; ClearSelect;
&amp;nbsp; // Get the corresponding IDs
IDs = dt1:ID[selectedRows];
&amp;nbsp; // Select the corresponding rows in dt2
selectMatchingRows( dt2, Expr( :ID ), IDs );
&amp;nbsp; // Select the corresponding rows in dt3
selectMatchingRows( dt3, Expr( :ID ), IDs );

);
);
// Assign the handler to dt1
rsh = dt1 &amp;lt;&amp;lt; MakeRowStateHandler( propagateSelectionToOtherTables );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code exclude the selected data at the very beginning (first selection in the master data table) but not afterward.&lt;/P&gt;&lt;P&gt;Are there any way to improve this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In advance thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Antoine Carré&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2024 07:15:52 GMT</pubDate>
    <dc:creator>STThunder</dc:creator>
    <dc:date>2024-08-29T07:15:52Z</dc:date>
    <item>
      <title>MakeRowStateHandler function: Exclude and Hide all but selected rows over different data table</title>
      <link>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789423#M96993</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to handle several Data Table and I would like to use only one filter. Ideally I would like to hide and exclude all the data that are not selected over different data table.&lt;/P&gt;&lt;P&gt;I used a modified version of a JSL code made my ian.cox@jmp.com, see below on JMP 17.0.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// ian.cox@jmp.com: 03Nove2014

// Demo of how to link multiple child tables to a parent table using a row state handler

Names Default To Here( 1 );

// Make some tables to use

dt1 = New Table( "Table 1",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Values( (1 :: 10)` ) ),&amp;nbsp;
New Column( "Response", Numeric, Continuous, Formula( Random Normal( 0, 1 ) ) )
);
dt1 &amp;lt;&amp;lt; Set Name ("dt1 Master");

dt2 = New Table( "Table 2",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 5 ) ) ),&amp;nbsp;
New Column( "Attribute 2", Numeric, Continuous, Formula( Random Integer( 0, 10 ) ) ),&amp;nbsp;
AddRows( 20 )
);
dt2 &amp;lt;&amp;lt; Set Name("dt2 - slave");

dt3 = New Table( "Table 3",&amp;nbsp;
New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 11 ) ) ),&amp;nbsp;
New Column( "Attribute 3", Numeric, Continuous, Formula( Random Integer( 0, 100 ) ) ),&amp;nbsp;
AddRows( 30 )
);
dt3 &amp;lt;&amp;lt; Set Name("dt3 - slave");
// Utility function:
// Given a data table, a column therein and some value(s) in that column, selects all corresponding rows.
// Need to allow for 'col' to be numeric (character), in which case 'vals' is a matrix (is a list).

selectMatchingRows =&amp;nbsp;

Function( {dt, col, vals},&amp;nbsp;
rows2select = [];
If( Is Matrix( vals ),&amp;nbsp;
&amp;nbsp; // 'col' is numeric
For( i = 1, i &amp;lt;= N Row( vals ), i++,&amp;nbsp;
rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) );
)
,&amp;nbsp;
&amp;nbsp; // 'col' is character
For( i = 1, i &amp;lt;= N Items( vals ), i++,&amp;nbsp;
rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) );
)
);

dt &amp;lt;&amp;lt; Select Rows( rows2select ) &amp;lt;&amp;lt; Hide &amp;lt;&amp;lt; Exclude;
/*
dt &amp;lt;&amp;lt; Exclude;
dt &amp;lt;&amp;lt; Hide;
*/
);

// Make a row state handler to be assigned to the 'master' table (dt1). Allow for multiple row selections.

propagateSelectionToOtherTables =&amp;nbsp;
Function( {x},&amp;nbsp;
&amp;nbsp; // Get the rows that have been selected
selectedRows = dt1 &amp;lt;&amp;lt; GetSelectedRows;
If( N Row( selectedRows ) &amp;gt; 0,&amp;nbsp;
&amp;nbsp; // Clear any existing selection
dt2 &amp;lt;&amp;lt; ClearSelect;
dt3 &amp;lt;&amp;lt; ClearSelect;
&amp;nbsp; // Get the corresponding IDs
IDs = dt1:ID[selectedRows];
&amp;nbsp; // Select the corresponding rows in dt2
selectMatchingRows( dt2, Expr( :ID ), IDs );
&amp;nbsp; // Select the corresponding rows in dt3
selectMatchingRows( dt3, Expr( :ID ), IDs );

);
);
// Assign the handler to dt1
rsh = dt1 &amp;lt;&amp;lt; MakeRowStateHandler( propagateSelectionToOtherTables );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code exclude the selected data at the very beginning (first selection in the master data table) but not afterward.&lt;/P&gt;&lt;P&gt;Are there any way to improve this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In advance thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Antoine Carré&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 07:15:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789423#M96993</guid>
      <dc:creator>STThunder</dc:creator>
      <dc:date>2024-08-29T07:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: MakeRowStateHandler function: Exclude and Hide all but selected rows over different data table</title>
      <link>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789503#M96995</link>
      <description>&lt;P&gt;I made some modifications to make the code work.&amp;nbsp; However, it isn't very robust code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// ian.cox@jmp.com: 03Nove2014

// Demo of how to link multiple child tables to a parent table using a row state handler

Names Default To Here( 1 );

// Make some tables to use

dt1 = New Table( "Table 1",
	New Column( "ID", Numeric, Conntinuous, Values( (1 :: 10)` ) ),
	New Column( "Response", Numeric, Continuous, Formula( Random Normal( 0, 1 ) ) )
);
dt1 &amp;lt;&amp;lt; Set Name( "dt1 Master" );

dt2 = New Table( "Table 2",
	New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 5 ) ) ),
	New Column( "Attribute 2", Numeric, Continuous, Formula( Random Integer( 0, 10 ) ) ),
	AddRows( 20 )
);
dt2 &amp;lt;&amp;lt; Set Name( "dt2 - slave" );

dt3 = New Table( "Table 3",
	New Column( "ID", Numeric, Conntinuous, Formula( Random Integer( 1, 11 ) ) ),
	New Column( "Attribute 3", Numeric, Continuous, Formula( Random Integer( 0, 100 ) ) ),
	AddRows( 30 )
);
dt3 &amp;lt;&amp;lt; Set Name( "dt3 - slave" );
// Utility function:
// Given a data table, a column therein and some value(s) in that column, selects all corresponding rows.
// Need to allow for 'col' to be numeric (character), in which case 'vals' is a matrix (is a list).

selectMatchingRows = 

Function( {dt, col, vals},
	rows2select = [];
	If( Is Matrix( vals ), 
  // 'col' is numeric
		For( i = 1, i &amp;lt;= N Row( vals ), i++,
			rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) )
		)
	, 
  // 'col' is character
		For( i = 1, i &amp;lt;= N Items( vals ), i++,
			rows2select = V Concat( rows2select, dt &amp;lt;&amp;lt; GetRowsWhere( col == vals[i] ) )
		)
	);
	//dt &amp;lt;&amp;lt; clear rowstates;
	dt &amp;lt;&amp;lt; Select Rows( rows2select ) &amp;lt;&amp;lt; Hide(1) &amp;lt;&amp;lt; Exclude(1);
	dt &amp;lt;&amp;lt; invert row selection;
	dt &amp;lt;&amp;lt; Hide(0) &amp;lt;&amp;lt; Exclude(0);
	dt &amp;lt;&amp;lt; invert row selection;
/*
dt &amp;lt;&amp;lt; Exclude;
dt &amp;lt;&amp;lt; Hide;
*/
);

// Make a row state handler to be assigned to the 'master' table (dt1). Allow for multiple row selections.

propagateSelectionToOtherTables = Function( {x}, 
  // Get the rows that have been selected
	selectedRows = dt1 &amp;lt;&amp;lt; GetSelectedRows;
	If( N Row( selectedRows ) &amp;gt; 0, 
  // Clear any existing selection
		dt2 &amp;lt;&amp;lt; ClearSelect;
		dt3 &amp;lt;&amp;lt; ClearSelect;
  // Get the corresponding IDs
		IDs = dt1:ID[selectedRows];
  // Select the corresponding rows in dt2
		selectMatchingRows( dt2, Expr( :ID ), IDs );
  // Select the corresponding rows in dt3
		selectMatchingRows( dt3, Expr( :ID ), IDs );
	,
		If( N Row( dt2 &amp;lt;&amp;lt; get selected rows ) &amp;gt; 0,
			dt2 &amp;lt;&amp;lt; Hide( 0 ) &amp;lt;&amp;lt; exclude( 0 );
			dt2 &amp;lt;&amp;lt; clear select;
		);
		If( N Row( dt3 &amp;lt;&amp;lt; get selected rows ) &amp;gt; 0,
			dt3 &amp;lt;&amp;lt; Hide( 0 ) &amp;lt;&amp;lt; exclude( 0 );
			dt3 &amp;lt;&amp;lt; clear select;
		);
	);
);
// Assign the handler to dt1
rsh = dt1 &amp;lt;&amp;lt; MakeRowStateHandler( propagateSelectionToOtherTables );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2024 09:30:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789503#M96995</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-08-29T09:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: MakeRowStateHandler function: Exclude and Hide all but selected rows over different data table</title>
      <link>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789548#M96997</link>
      <description>&lt;P&gt;Quite a few assumptions made but this might work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt1 = New Table("Table1",
	New Column("ID", Numeric, Ordinal, Values((1 :: 10)`)),
	New Column("Response", Numeric, Continuous, Formula(Random Normal(0, 1)))
);

dt2 = New Table("Table2",
	New Column("ID", Numeric, Ordinal, Formula(Random Integer(1, 5))),
	New Column("Attribute 2", Numeric, Ordinal, Formula(Random Integer(0, 10))),
	AddRows(20)
);

dt3 = New Table("Table3",
	New Column("ID", Numeric, Conntinuous, Formula(Random Integer(1, 11))),
	New Column("Attribute 3", Numeric, Continuous, Formula(Random Integer(0, 100))),
	AddRows(30)
);


set_states = function({dt, ids}, {Default Local},
	rows_to_show = dt &amp;lt;&amp;lt; Get Rows Where(Contains(sel_ids, :ID));
	rstates = J(N Rows(dt), 1, 6); 
	rstates[rows_to_show] = 0;
	dt &amp;lt;&amp;lt; Set Row States(rstates);	
);

Eval(EvalExpr(
	handler = Function({a},
		Try(
			sel_rows = Expr(dt1) &amp;lt;&amp;lt; Get Selected Rows;
			sel_ids = Expr(dt1)[sel_rows, "ID"];
			set_states(Expr(dt2), sel_ids);
			set_states(Expr(dt3), sel_ids);
		,
			show(exception_msg);
		);
	);	
));

rsh = dt1 &amp;lt;&amp;lt; Make Row State Handler(handler);

/*
nw = New Window("demo",
	H List Box(
		Panel Box("Table1 (parent table)",
			dt1 &amp;lt;&amp;lt; new data box
		),
		V List Box(
			Panel Box("Table 2 (child table)",
				dt2 &amp;lt;&amp;lt; new data box
			),
			Panel Box("Table 3 (child table)",
				dt3 &amp;lt;&amp;lt; new data box
			)
		)
	)
);
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to note: row states break very easily. Depending on what you are trying to do, you might want to use some other solution than row state handler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 10:43:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/789548#M96997</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-29T10:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: MakeRowStateHandler function: Exclude and Hide all but selected rows over different data table</title>
      <link>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/793508#M97087</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Super exactly what I was looking for. Thanks a lot for the reactivity and the quality of the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Antoine&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2024 06:37:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/MakeRowStateHandler-function-Exclude-and-Hide-all-but-selected/m-p/793508#M97087</guid>
      <dc:creator>STThunder</dc:creator>
      <dc:date>2024-09-02T06:37:54Z</dc:date>
    </item>
  </channel>
</rss>

