- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
List box showing all open tables
I'm trying to build a listbox which lists down all the opened data table and gets updated automatically with newly opened / newly closed table. I've started with the script below but for some reason the onClose function doesn't work.
Appreciate the help
names default to here(1);
f1 = function ({Temp_list},
T_list = Temp_list << get name();
lb << remove all;
lb << append (T_list)
);
f2 = function ({Temp_list},
T_list = Temp_list << get name();
lb << remove all;
lb << append (T_list)
);
asub = Subscribe to data table list( , onopen(f1));
Subscribe to data table list(asub , onclose(f2));
nw = new window("Trial",show menu(0),
vlistbox(
T_list = get data table list ();
lb = listbox(T_list);
)
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
You should just be able to add new values to lb and them remove just the closed one with index (using Contains() to get index) also added local variables to functions.
Names Default To Here(1);
f1 = function ({Temp_list}, {tableList},
tableList = Temp_list << get name();
lb << append (tableList)
);
f2 = function ({Temp_list}, {tableList},
tableList = Temp_list << get name();
lb << Remove Item(Contains(lb << get items, tableList));
);
asub = Subscribe to data table list( , onopen(f1));
Subscribe to data table list(asub , OnClose(f2));
nw = new window("Trial",show menu(0),
vlistbox(
lb = listbox(get data table list ());
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
Using the below JSL, here is what I have discovered.
Names Default To Here( 1 );
f2 = Function( {Temp_list},
T_list = Get Data Table List();
lb << remove all;
lb << append( T_list );
show("Close");
);
f1 = Function( {Temp_list},
T_list = Get Data Table List();
lb << remove all;
lb << append( T_list );
show("add");
);
asub = Subscribe to Data Table List( , onopen( f1 ) );
Subscribe to Data Table List(asub , onclose( f2 ) );
nw = New Window( "Trial",
Show Menu( 0 ),
V List Box(
T_list = Get Data Table List();
lb = List Box( T_list );
)
);
- The created list box will Add new data tables without error.
- The f1 function is executed once for each addition
- If you close a data table, it will not be removed from the list box.
- If you close a second data table, the previous closed data table will be removed from the list box.
- If you close the list box and run the JSL for a second time, and close a data table, an f2 function will be run twice. The f2 function from the first running of the JSL will be run, followed by the running of the second instance of the f2 function. This can be shown by changing the Show() statement. If the Show statement was changed from
toShow( "Close" );
Show( "Close 2" );
upon closing a data table, both versions of the Show() statement will be displayed,
- Subsequent executions of the JSL add additional copies of the f2 function, with each copy being executed for each data table closing.
- Clear Globals and Clear Symbols does not eliminate the previous versions of the f2 function.
This is clearly a JMP bug and needs to be sent into the JMP Support Staff.
I have submitted the bug to them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
Thanks @txnelson !! That's exactly the bug which I encountered. I guess in the meantime I'll have to find a workaround for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
I'm bumping this topic with some new findings, maybe it will help someone. I was trying to do something similar as @Djtjhin and encountered all the same problems described here, which I mostly solved thanks to the discussion here.
What I can add is the explanation of the weird behavior described by @txnelson. The issue is that if you subscribe without explicitly stating the subscription name as below:
asub = Subscribe to data table list( , OnOpen( Show("opening...") ) )
a new subscription under a new generic name ("_DTListSubscriber123") is created each time you run the script, increasing counter at the end.
The trick is either to explicitly name the subscriber so that you overwrite the same one each time you run the script, e.g.:
asub = Subscribe to data table list( "MyDTLSub1", OnOpen( Show("opening...") ) )
or to unsubscribe at the end, e.g. in the <<On Close statement of the window:
Unsubscribe to data table list( asub, "ALL" )
In other news, @Djtjhin, for renaming it's works pretty simply, it seems the event is triggered AFTER renaming, so Get Data Table List() gets you the new name(s). But I was pulling my hair out from a different reason, before making it work, due to lack of documentation. In contrast to OnOpen and OnClose, the OnRename function needs 2 arguments (new and old name/table), otherwise you'll be getting errors. And although in this particular listbox example you don't actually need them, if you do, you also have to keep in mind they are of different variable type, one is a table, the other a string (see below).
Names Default To Here(1);
f = Function ( { new_name_as_table, old_name_as_string },
print(asub||" renaming: "|| old_name_as_string || " to " || (new_name_as_table << get name) );
lb << set items( Get Data table List() );
);
asub = Subscribe to data table list( "MySub", OnRename( f ) );
nw = new window("Trial",show menu(0),
<< On Close(Unsubscribe to data table list( asub, "ALL")),
vlistbox(
lb = listbox(get data table list ());
)
);
dt = Open( "$SAMPLE_DATA/Tiretread.jmp" );
dt << set name( (dt<<get name) || "_renamed" );
Otherwise I agree with general sentiment that the subscriber it's very hard to work with, you have to be really careful to tie up all the loose ends. Better documentation would be much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
You should just be able to add new values to lb and them remove just the closed one with index (using Contains() to get index) also added local variables to functions.
Names Default To Here(1);
f1 = function ({Temp_list}, {tableList},
tableList = Temp_list << get name();
lb << append (tableList)
);
f2 = function ({Temp_list}, {tableList},
tableList = Temp_list << get name();
lb << Remove Item(Contains(lb << get items, tableList));
);
asub = Subscribe to data table list( , onopen(f1));
Subscribe to data table list(asub , OnClose(f2));
nw = new window("Trial",show menu(0),
vlistbox(
lb = listbox(get data table list ());
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
Thanks @jthi ! That works!
If you don't mind, could you also show how you would set up the "OnRename" clause as well ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List box showing all open tables
After testing Subscribe to data table list a bit more, I would avoid it if possible. It doesn't seem to work well at all, events not triggering, fairly bad documentation on how it should be used and so on. I'm using JMP16.1.0 Pro on Windows 10.
I have one application where I would like to have something like this, but I think I will just add Refresh datatable list or something similar.