-1

Hi I am using jqGrid for showing the grid values dynamically but i need to hide edit add option showing only based on logged in user role but in navGrid I am not able to place the if and else condition please help me my code is:

.navGrid('#pagernav',
{

    edit: true,
    add: true,
    del: false,
    search: true,
    refresh: true,
    closeAfterSearch: true
},

In the above code edit and add options needs to display only based on logged in user example logged in user is admin this options need to display otherwise it has to disable

Oleg
  • 220,925
  • 34
  • 403
  • 798

1 Answers1

0

You have many options to implement your requirements:

1) The most easy implementation if you could set some JavaScript variable, like for example the global variable isReadOnly, based on logged in user role. Then your could could be just like

.navGrid('#pagernav',
{

    edit: !isReadOnly,
    add: !isReadOnly,
    del: false,
    search: true,
    refresh: true,
    closeAfterSearch: true
}

2) You can create the navigator bar with Add and Edit buttons and to hide there depend on some conditions, which you evaluate later dynamically. You need just execute the code like $('#add_list,').hide() or $('#add_list,#edit_list').hide(), where the list part of the id is the grid id. See the old answer for more details.

3) You can use the same ids of the Add and Edit buttons, like in the way 2, but remove the buttons instead of hiding there. You need just use jQuery.remove method instead of jQuery.hide.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798