1

I want to use different navigator buttons in jqGrid depending on login status. for example: if the user is logged in then add/delete/edit button appeared.

Any ideas?

Thanks in advance.

heiko
  • 11
  • 1

2 Answers2

1

It is possible to add buttons programmatically using the navButtonAdd method (for the navigation bar) and the toolbarButtonAdd method for the toolbar. For example:

        jQuery("#grid").toolbarButtonAdd('#t_meters',{caption:"MyButton",
         id: "t_my_button",
         title: "Do my button action",
         buttonicon: 'ui-icon-edit',
         onClickButton:function(){
           // Button handle code goes here...
         }
        });

And:

        jQuery("#grid")..navButtonAdd('#pager',{
         id: "t_my_button",
         title: "Do my button action",
         buttonicon: 'ui-icon-edit',
         onClickButton:function(){
           // Button handle code goes here...
         }
        });

For more information see the Custom Buttons on the Wiki.

Anyway, once this code is in place, you can detect login status server-side. Then use this knowledge to generate client code that only adds the buttons to your grid if the user is supposed to have access to them.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
1

You can also use for example userdata (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#user_data) to send information about buttons which you need to have in the navigator. userdata should be set by server. Then with respect of:

var navGridParams = jQuery("grid_id").getGridParam('userData');
// var navGridParams = { edit: false, add: false, search: true }

you can get the data set by the server.

Now the typical call like:

jQuery("grid_id").navGrid('#pager', { edit: false, add: false, search: true });

You should place not after creating of jqGrid, but inside of than inside of loadComplete. So the code could looks like following:

var isNavCreated = false;
jQuery('#list').jqGrid({
    // ...
    loadComplete: function () {
        var grid = jQuery("grid_id");
        if (isNavCreated === false) {
            isNavCreated = true;
            var navGridParams = grid.getGridParam('userData');
            grid.navGrid('#pager', navGridParams);
        }
    },
    // ...
});

Another option that I see, is to use cookie instead of userdata to send information about navGridParams back to the client.

Jess Stone
  • 677
  • 8
  • 21
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I can't understand how this `userdata` will help to this login status issue. any example here related this issue? – CJ Ramki Jul 29 '14 at 10:40
  • 1
    @CJRamki: It's very easy. `navGridParams` should be something like `{ edit: false, add: false, search: true }`. If you create navigator **after the first response from the server** then the server can place `userdata: { edit: false, add: false, search: true }` in the response (see [here](http://stackoverflow.com/a/3849513/315935) or [here](http://stackoverflow.com/a/3128934/315935)). So the server can fill `userdata` based on **the right of the user**. – Oleg Jul 29 '14 at 10:46
  • 1
    @CJRamki: [The answer](http://stackoverflow.com/a/7057838/315935) suggest to create *all navigator buttons* first and hide/show the buttons later (based on the server response for example). [Another answer](http://stackoverflow.com/a/5376355/315935) shows how to **disable** navigation buttons instead of hiding. – Oleg Jul 29 '14 at 10:49
  • I simply removed that node using condition like this ` $('#add_myGrid').remove(); ` It's working well... – CJ Ramki Jul 29 '14 at 11:48