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
zhouye0
Level II

Interactive Data Table selector

Is there a way to script this following data table list select part into a jsl script?

11655_pastedImage_5.png

As of now I have a script done, but only on one data table at a time, is there a function that I can call to make a data table list selector like the picture that I attached above, and upon selection, I can have my current data table updated accordingly? My not-so-flexible script now looks like this

11656_pastedImage_6.png

I want to achieve this

11655_pastedImage_5.png

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Interactive Data Table selector

Maybe something like this:

NamesDefaultToHere(1);

dtNames = {};

For(t=1, t<=NTable(), t++,

InsertInto(dtNames, DataTable(t) << getName);

);

nw =

NewWindow("Test",

PanelBox("Pick a table",

dtlb = ListBox(dtNames, MaxItems(1))

),

ButtonBox("OK", OKscript)

);

OKScript =

Expr(

nw << closeWindow;

dtName = dtlb << getSelected;

if(NItems(dtName) > 0,

Print("Table selected: "||dtName[1])

,

Print("No table selected")

)

);


View solution in original post

11 REPLIES 11
ian_jmp
Level X

Re: Interactive Data Table selector

Maybe something like this:

NamesDefaultToHere(1);

dtNames = {};

For(t=1, t<=NTable(), t++,

InsertInto(dtNames, DataTable(t) << getName);

);

nw =

NewWindow("Test",

PanelBox("Pick a table",

dtlb = ListBox(dtNames, MaxItems(1))

),

ButtonBox("OK", OKscript)

);

OKScript =

Expr(

nw << closeWindow;

dtName = dtlb << getSelected;

if(NItems(dtName) > 0,

Print("Table selected: "||dtName[1])

,

Print("No table selected")

)

);


zhouye0
Level II

Re: Interactive Data Table selector

Thanks Ian for the help, I have a follow up question if you don't mind. Now that I have a way to get the list of all the data tables, to update the script the run all the operations on the newly selected data table, is is recommended to call the exact same script (with newly chosen data table) through recursion? Or is there a function that I'm unaware of that can quickly refresh the script and run it on the new data table that I selected?

ian_jmp
Level X

Re: Interactive Data Table selector

I think the answer depends on how you have engineered the other parts of the UI to support the workflow you want. But I don't think you need any recursion.

For example, if you also have a 'ColListBox()' to display the columns of the table that has been selected via the above method, you could attach a script to 'dtlb' (defined above) so that (when the table selection is made or changed) it automatically updates the list of available columns. Similarly, you could tie a script to the 'ColListBox()' that makes or updates a report window (assuming you need only one column for your analysis).

(Without seeing more details, it's a little difficult to be more helpful).

zhouye0
Level II

Re: Interactive Data Table selector

Sorry, I should have provided more details, You are right, I have a Col List Box somewhere below that I would like to update automatically showing the columns according to the table I selected

11657_pastedImage_0.png

Can you elaborate more on attaching a script to dtlb? Defined above, dtlb = ListBox(dtNames, MaxItems(1))


pmroz
Super User

Re: Interactive Data Table selector

This presentation on Application Builder should be helpful.  Among other things it shows how to populate a list box dynamically with column names when a particular table is chosen.

zhouye0
Level II

Re: Interactive Data Table selector

Hi PMroz, I read the presentation and am now aware that it can be done easier and much more interactive if done using the application builder, but at this point (a thousand lines into the script), it would probably take some time to rebuild it in the application builder. Is there a way to make it auto-refresh the columns as I select the table and click the button box without porting everything to the application builder?

pmroz
Super User

Re: Interactive Data Table selector

Try this code:

// Preload the table combobox with a list of existing tables

default_table = current data table() << get name;

table_list = {};

ntables = ntable();

For (i = 1, i <= ntables, i++,

      one_name = Data Table(i) << Get Name;

      table_list[i] = one_name;

// For the default table load up the columns list box

      if (one_name == default_table,

            idefault = i;

            col_list = data table(i) << get column names (as string);

      );

);

nw = new window("Test",

      select_table_combo = combobox(table_list,

// This function is called when the Combo Box selection changes

            selectedIndex = select_table_Combo << Get Selected;

            col_list = data table(selectedIndex) << get column names (as string);

//          columns_listbox << remove all;

            columns_listbox << set items(col_list);),

      columns_listbox = listbox(col_list);

);

zhouye0
Level II

Re: Interactive Data Table selector

Hi PMroz,

That works excellent for me, I integrated it into my script and realized that I mis-used a word up there, I was using a Filter Col Selector instead of a col list box, I see your way of doing it is setting and updating the new set of columns from the table based on the selected data table, and the part that refreshes it is when you call

columns_listbox = listbox(col_list);

to display the newly updated table. So I tried to replicate it for the "filter col selector".

1) I modified a bit of your code so that it doesnt appear in a new window and goes to my original window

2) I modified the Filter Col Selector to the "SelectedIndex" variable and call it below in hopes that it would update, but obviously I'm doing it wrong. Do you know the right way to refresh the Filter Col Selector like how you did for the Col List Box? I'd like to apply your working method for the Col List Box to the Filter Col Selector

11666_pastedImage_5.png

This is my code for the Filter Col Selector

       param = Filter Col Selector(data table(selectedIndex),

              all,

              width( 250 ),

              colname = param << get selected();

              colStatInfo(colname[1]);

              list << inval;

              list << updateWindow;

              list << reshow;     

              ),

             

              param << nominal( 0 );

              //param << Name contains( " " );

             

       )

ComplexNerd
Level III

Re: Interactive Data Table selector

@pmroz Hello could you share the presenation link to the application builder again. I have the same use case but the link seems to have been archived.