views:

47

answers:

2

Hi all,

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.

A: 

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
A: 

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 which I see is to use cookie instead of userdata to send information about navGridParams back to the client.

Oleg