Author Topic: Change context menu name dynamically after load  (Read 411 times)

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Change context menu name dynamically after load
« 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"
}
}
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Change context menu name dynamically after load
« Reply #1 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
« Last Edit: January 19, 2023, 05:34:20 pm by paramvir »

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Re: Change context menu name dynamically after load
« Reply #2 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.

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Re: Change context menu name dynamically after load
« Reply #3 on: January 23, 2023, 11:56:01 am »
Please advise on this.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Change context menu name dynamically after load
« Reply #4 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";
})
« Last Edit: January 23, 2023, 04:10:53 pm by paramvir »