views:

212

answers:

2

Hey guys,

Did you guys know how to prevent the open of a Form when I click on a add button?

Maybe using beforeShowForm?

function(formid)
{
    if(jQuery('#gridap').getGridParam('selrow'))
    {

        idgridap=jQuery('#gridap').getGridParam('selrow');
        jQuery('#FK_numerocontrato_ap',formid).val(idgridap).attr('readonly','readonly');

    }
    else 
    {
         // I want to prevent the openning of the add form here and maybe show an alert using the "alertcap"

    }
}
CHECAROW;

$grid->setNavEvent('add','beforeShowForm',$checarowid);

BTW, there's a way to call the alertmod of jqgrid and add a custom message to it?

tks!

A: 

I don't understand why you not just remove "Add" button from the navigation bar. To create a navigation bar you explicitly call navGrid method of jqGrid

jQuery("#grid_id").navGrid('#gridpager'); 

or

jQuery("#grid_id").jqGrid('navGrid', '#gridpager');

but navGrid has additional parameters (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator). So if you use

jQuery("#grid_id").navGrid('#gridpager', {add: false}); 

you will be have no "Add" button.

If you do need have "Add" button, please explain your situation more clear. By the way with the way described in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons you can add an custom button with full control from your side. The name of icon you can find on the page http://jqueryui.com/themeroller/ if you place a cursor over the icon on the "Framework Icons" area on the bottom of the page. The custom button can have the same icon as the "Add" button has. Can it solve your problem?

UPDATED: Now after your comment I understand your problem. I can suggest to use addfunc option of navGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator&s[]=navgrid). So the code could looks like following:

var grid = jQuery("#grid_id").navGrid('#gridpager', {addfunc: function() {
    var sel_id = grid.getGridParam('selrow');
    if (sel_id) {
        grid.editGridRow("new", pAddOption);
    } else {
        viewModal("#alertmod", { gbox: "#gbox_" + grid_id, jqm: true });
        jQuery("#jqg_alrt").focus();
    }
}});

In this example will be allowed to click "Add" button only if a row is selected. You will see a message box with the text like "Please, select row" (the text which defines $.jgrid.nav.alerttext inside of grid.locale-en.js or other localization file which you use). You can place this code fragment in your master grid.

The code in case of denying of "Add" operation can be easier, I just copied here a code fragment which use jqGrid itself. You can display your custom error message instead.

Oleg
Hello Oleg,First, I have 2 grids, a master and a slave, when I click in a row on the master grid the information about it shows up on the slave grid.When I click on the add button, I want to check if the master grid has a selected row, In the slave nav, I have a add, edit and a refresh button, I want to prevent the openning of the "add form" and show a custom message if there´s no row selected on the master grid.Tks Oleg! ;-)
Jonathan
A: 
Jonathan