cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to get data selected by Data Filter () into a new data table (using JSL)?

I know how to do this interactively but how do to get data selected by Data Filter () from a parent data-table into a new (subset) data table via JSL? I also need the new subset data-table to be created newly (closing the old subset) or the old one refreshed (if this possible) as the selection changes in the data filter.

Would putting the data filter () inside a modal window work or is there a better more elegant option?

 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

Wouldn't it just be easier to let user make all the selections and then make them press OK when they are ready?

-Jarmo

View solution in original post

9 REPLIES 9
jthi
Super User

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

What type of data filter you have and where? How user performs selections (should only the selections done on data filter be used)? What is the resulting table being used for?

 

Check scripting index for Data Filter

jthi_0-1686761432752.png

Get Filtered Rows, Get Where Clause, Show Subset as some options

-Jarmo
hogi
Level XII

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

Best is to use a local data filter - a global data filter changes the row states of the data table.

If you have a window with such a local data filter (first part), you just have to run this code - and will get a corresponding subset.
The code can be used for every Report window - and could be added as a Toolbar Shortcut.
Alternatively, one could add a Button Box to the window to trigger the generation of the subset table.

 

Names Default to Here(1);
/*dt0 = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt0 << Graph Builder(
	Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
	Elements( Points( X, Y ) ),
	Local Data Filter(
		Add Filter( columns( :sex ), Where( :sex == "F" ) )
	)
);*/
	
	
ldf = Try( Current Report()["Local Data Filter"] << get scriptable object, Stop() );
dt = ldf << Get Data Table();
WhereClause = ldf << Get where clause();
If( Not( Is Missing( WhereClause ) ),
	Eval( Parse( Substitute( ldf << Get where clause(), "Select Where", "myRows= dt << get rows where" ) ) );
	dt << subset( Rows( myRows ), Selected columns only( 0 ) );
);


Alternatively .... *)

Neo
Neo
Level VI

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

@jthi It is Data Filter ()

 

This is what I have got so far. It partially works. I need the table to update or generate new one if the selection changes. How  to do that in JSL (on Close ()) ?

 

Names Default To Here (1);
dt = Current Data Table();

nw = New Window("Select Parameters", << modal, << return result,
obj = dt << Data Filter(
	//Location( {3000, -600} ),
	Width( 315 ),
	Conditional,
	Add Filter(
		columns( :Col1, :Col2, :Col3, :Col4),
		Display( :Col2, "Check Box Display" ),
		Display( :Col3, "Check Box Display" ),
		Display( :Col4, "Check Box Display" ),
		Display(
			:Parameter,
			N Items( 20 ),
			"Check Box Display",
			Find( Set Text( "" ) )
		)
	)
);
);

//obj << Get Filtered Rows;

dtNew = dt << subset( selected columns(1), selected rows(1));

I start with all boxes unchecked for the user to select based on which the data table is generated. Get Filtered Rows does not seem to work in my case. 

 

When it's too good to be true, it's neither
jthi
Super User

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

You want new table generated each time the selection changes? Or do you want to have modal which will continue after user has made the selections?

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("Select Parameters",
	<<modal,
	<<return result,
	V List Box(
		obj = dt << Data Filter(
		//Location( {3000, -600} ),
			Width(315),
			Conditional,
			Add Filter(
				columns(:name, :age, :sex),
				Display(:Col2, "Check Box Display"),
				Display(:Col3, "Check Box Display"),
				Display(:Col4, "Check Box Display"),
				Display(:Parameter, N Items(20), "Check Box Display", Find(Set Text("")))
			)
		),
		H List Box(
			Button Box("OK"),
			Button Box("Cancel")
		)
	)
);

dtNew = dt << subset(selected columns(1), selected rows(1));
-Jarmo
Neo
Neo
Level VI

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

@jthi  I would prefer a new table be generated each time the selection changes deleting the old values in the table (useful for what I want to do next). I do not know how to do this hence did the modal approach. 

When it's too good to be true, it's neither
jthi
Super User

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

You can use filter state handler to trigger "events" when selection in filter is changed.

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

f = Function({a}, 
	Show(obj << get filtered rows);
);

nw = New Window("Select Parameters",
	<<modal,
	<<return result,
	V List Box(
		obj = dt << Data Filter(
		//Location( {3000, -600} ),
			Width(315),
			Conditional,
			Add Filter(
				columns(:name, :age, :sex),
				Display(:Col2, "Check Box Display"),
				Display(:Col3, "Check Box Display"),
				Display(:Col4, "Check Box Display"),
				Display(:Parameter, N Items(20), "Check Box Display", Find(Set Text("")))
			)
		),
		H List Box(
			Button Box("OK"),
			Button Box("Cancel")
		)
	),
	rs = obj << Make Filter Change Handler(f);
);
-Jarmo
Neo
Neo
Level VI

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

@jthi Thanks for pointing towards the filter state handler. However, your script does not exactly do as I would like for the "replace existing data table with new data" way of doing this. The data filter window needs to remain open and the data populated/updated/regenerated in "dtNew" as the user changes selection. Possible?

 

When it's too good to be true, it's neither
jthi
Super User

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

Wouldn't it just be easier to let user make all the selections and then make them press OK when they are ready?

-Jarmo
hogi
Level XII

Re: How to get data selected by Data Filter () into a new data table (using JSL)?

How about Dynamic Subset Add-In (Filterable Data Table, updated) ?

edit:
*) I just found the discussion again -  and it seems that I had the same idea "again" as some posts before
- so I deleted the first link