Search code examples
jqueryjqgrid

how to disable the plus icon from jqgrid?


I want to disable the plus icon from my jsp page when the request is made to this page. How to do this?

I tried this

if ($("#errorMsgForItem").val() == "noloc") 
                    {
                        $("#add_" + myGrid[0].id).addClass('ui-state-disabled');
                        console.debug("No Item location found...");

                    }

Update: More code


This is a function(createNew) which will be called on the same page After submitting a form via AJAX

function createNew(aDateVal){
$("#searchProductDiv").css("display","block");
     $("#itemfilterParamDiv_org").css("display","none");
$('#createNewInventoryBlock').dialog('close');
 $("#saveSubgridItem").show();

 if(aDateVal == null || aDateVal == ""){
        $("#dateValidationMsg").html("Enter date");
        $("#saveSubgridItem").hide();
      }else{
          blockPanel("centerPanel");
         $.ajax({
          url: "validationAgainstExistData.htm?date="+aDateVal+"&dateFormat="+controllerDateFormat,
          success: function(data){
            $("#errorMsgForItem").val( $.trim(data));
                if ($("#errorMsgForItem").val() == "yes") 
                {
                    $("#dateValidationMsg").hide();
                    $("#errorMsgDisplay").show();
                    $("#errorMsgDisplay").html("Inventory for the selected date already exists. Click on the inventory date to open it for edit."); 
                    $("#centerPanel").unblock();
                }else{

                    //$("#itemLocationGrid").jqGrid("navGrid", "#itemLocationGridPager", {add: false});
                    var msg =null;
                    $("#dateValidationMsg").hide();
                    $("#errorMsgDisplay").hide();
                     $("#itemLocationGridContainer").show();
                       loadItem(aDateVal,msg);
                    $("#categoryDisplayId").show();
                    $("#modifiedUserLabelId").show();
                    $("#userListDisplayTitleId").show();
                    //$('#itemLocationGrid').jqGrid().trigger('reloadGrid');
                    //$("#itemLocationGridContainer,#itemLocationGrid").jqGrid("navGrid", "#itemLocationGridPager", {add: false});

                    var myGrid = jQuery("#itemLocationGridContainer");//itemLocationGrid
                    $("#edit_" + myGrid[0].id).addClass('ui-state-disabled');
                    $("#del_" + myGrid[0].id).addClass('ui-state-disabled'); 
                    $("#add_" + myGrid[0].id).addClass('ui-state-disabled'); //nothing happening


                    $("#centerPanel").unblock();  
                       // $("#createNewInventoryBlock").dialog({autoOpen: true });
                    }
              }
        }); 
    }

}

html

<div id="searchProductName" style="display:none"></div>
<div id="itemLocationGridContainer" style="float:left;margin-top: 20px;display:none" >
    <p class="ui-widget" style="font-size: 12.5px;color: blue;">During editing a cell, do not drag the rows for rearranging.</p>
     <table id='itemLocationGrid'></table>
     <div id='itemLocationGridPager'></div>
     <div id ="addProduct" style="display:none;background-color:#DFEFFC;width:340px;height:auto;opacity: 0.99;filter:alpha(opacity=65);"></div>
      <div id ="productItemLocationId" title="Location "></div>
      <div style="display: none;" id="calculateItemSummariesBasedOnItemCategory"></div>
</div>

Solution

  • addClass('ui-state-disabled') disables the Add button instead of hiding. You can use jQuery.hide to hide it instead:

    var myGrid = $("#grid");
    
    // hide Add button
    $("#add_" + myGrid[0].id).hide();
    

    I should remark that you should use above code only if you need **dynamically* show or hide add button. If you don't need the button you should just use add: false option of navGrid method:

    // create navigator with Edit and Delete buttons, without Add button
    $("#grid").jqGrid("navGrid", "#pager", {add: false});
    

    If you do need dynamically hide/show some navigator buttons you should create all the buttons and hide/show the buttons when it's require. See the answer and another one for demos which explain more detailed the working with navigator buttons.