Page 1 of 1

Hide custom action button

Posted: 2021-04-27 17:16
by pfrumkin
Hi,

I have implemented a custom button using the actionbuttons.group.addbutton method. I need to hide it in some cases, once it is added how can I hide it?

Thanks.

~Paul
AG 5.84

Re: Hide custom action button

Posted: 2021-04-27 18:14
by jsetzer
You can use the return value of addButton function:

Code: Select all

var dv = AppGiniHelper.dv;
var grp = dv.getActionButtons().addGroup("Group (1)");
var btn = grp.addButton("Button (1)", function (e) {  /* your fn */ });

console.log("id of button: " + btn.id);
chrome_tJ1CPmCNOR.png
chrome_tJ1CPmCNOR.png (4.73 KiB) Viewed 4021 times

Console output:

chrome_yzXWKUm1eK.png
chrome_yzXWKUm1eK.png (2.43 KiB) Viewed 4021 times

--
Later on, you can use the id for accessing the button by id:

Code: Select all

var hide_button = true; // your condition

if (hide_button)
    jQuery(`#${btn.id}`).hide();
PS: the id's will not persist between page loads
PPS: you can also get the id of the group and access the group element

Re: Hide custom action button

Posted: 2021-04-27 20:31
by pfrumkin
Awesome, thanks Jan! :D

To hide I had to use

Code: Select all

$j("#" + btn.id).hide();
~Paul

Re: Hide custom action button

Posted: 2021-04-27 20:40
by jsetzer
Yes, string concatenation with + in javascript will work, too.

The `${variable}` notation seems new to many javascript developers. I don't see it very often. For me this is very useful and I got used to using that template-like string building instead of + concatenation.