Abb
Abb

Reputation: 3061

Enable or Disable selection of a Check Box in jqgrid depending on some specific column value

I have a jqgrid, where I want to select the rows which has value "Running" in Agent Status Column. For rest of the status, I should not be able to select the row.

The JQGrid code

 datatype: "json",
    contentType: 'application/json',
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    colNames: ['Id', 'Machine Name', 'IP Address', 'Discovered Date', 'Agent Install Status', 'Agent Installation Date', 'Agent Status', 'Agent Version', 'Last HeartBeat Recieved'],
    colModel: [            
        { name: 'id', hidden: false, width: 15, key: true },
        { name: 'machineName', width: 120 },
        { name: 'ipAddress', width: 60 },
        { name: 'discoveredDate', width: 110, formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'l, F d, Y' } },
        { name: 'agentInstallStatus', width: 70 },
        { name: 'agentInstallationDate', width: 110, formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'l, F d, Y' } },
        { name: 'agentStatusName', width: 90 , edittype:'select', editoptions:{value:"Running"} },
        { name: 'agentVersion', width:50},
        { name: 'lastHeartBeatRecieved', width: 110, formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'l, F d, Y' } }
    ],
    sortname: 'id',
    sortorder: 'asc',
    loadonce: true,
    viewrecords: true,
    gridview: true,      
    width: gwdth,
    height: 650,
    rowNum: 10,        
    rowList: [10, 20, 30],
    mtype: 'GET',
    multiselect: true,
    multipleSearch: true,
    pager: "#jqGridPager"
});

enter image description here

Is it possible that I show checkBoxes only for the Running Status?

I am completely new to this environment.

Upvotes: 3

Views: 5615

Answers (1)

Oleg
Oleg

Reputation: 221997

I see two main options to implement your requiremens:

  • use rowattr callback to disable the rows based on the content of "agentStatusName" column. See the demo created for the answer.
  • use beforeSelectRow callback (and onSelectAll too) to prevent selection of rows based on the content of "agentStatusName" column.

The first choice is the mostly simple and safe. The second one is more flexible. One can allow to edit rows (if it is required), but still prevent selection.

Upvotes: 2

Related Questions