ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: pranit@srcomsec on January 18, 2023, 08:46:30 pm

Title: Change context menu name dynamically after load
Post by: pranit@srcomsec on January 18, 2023, 08:46:30 pm
I need to change the context menu name on the specific event.

I am trying with below code and it is not working. Please advise.
Code: [Select]
{
name: 'Pause Grid',
action: function () {
var lochkPauseID = this.element[0].id.replace("gridfilter", "chkPausetbl");
$("#" + lochkPauseID).prop("checked", !$("#" + lochkPauseID).is(':checked'));

if ($("#" + lochkPauseID).is(':checked'))
{
alert(("Grid Paused.");
this.name = "UnPause Grid"
}
else
{
alert("Grid UnPaused.");
this.name = "Pause Grid"
}
}
}
Title: Re: Change context menu name dynamically after load
Post by: paramvir on January 19, 2023, 05:30:22 pm
you can use callback variant to create dynamic context menu or a specific dynamic menu item.

In the callback you can check the condition: if ($("#" + lochkPauseID).is(':checked')) and name the menu item accordingly.

API:

https://paramquery.com/pro/api#option-contextMenu
Title: Re: Change context menu name dynamically after load
Post by: pranit@srcomsec on January 20, 2023, 08:41:26 pm
I am trying to check for a sample code but not getting it.

Please share the sample code to change the existing context menu name.
Title: Re: Change context menu name dynamically after load
Post by: pranit@srcomsec on January 23, 2023, 11:56:01 am
Please advise on this.
Title: Re: Change context menu name dynamically after load
Post by: paramvir on January 23, 2023, 04:03:15 pm
This example: https://paramquery.com/pro/demos/context_menu shows 2 ways to change the menu item properties including the menu item names.

Code: [Select]
{
    name: this.option('filterModel.header') ? 'Hide filter row' : 'Show filter row',
    action: function(){
        this.option('filterModel.header', !this.option('filterModel.header'));
        this.refresh();
    }
},

Code: [Select]
$("#change_img_menu").click(function () {
    var items = grid.option('contextMenu').imgItems;
    items[0].name = "custom name";
})