3

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.

Abb
  • 3,051
  • 3
  • 17
  • 34

1 Answers1

2

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for the answer.. It worked for me, I just needed to add rowattr callback for the second link provided by you. – Abb Nov 22 '15 at 12:16
  • is it possible that I can disable only the Check Box column instead of the entire row? If yes, Could you please share a demo link – Abb Nov 25 '15 at 05:59
  • 1
    @AbhishekPandey: 1) The current code of free jqGrid from GitHub support [hasMultiselectCheckBox](https://github.com/free-jqgrid/jqGrid/blob/master/js/grid.base.js#L2022-L2023) callback which can be used to **remove** the checkboxes from some rows (based on the content). 2) if you don't want to remove checkbox, but to disable only, you can use `cellattr` in `cb` column (callback can be set in `onInitGrid`). `cellattr` can set the same classes like `rowattr`. – Oleg Nov 25 '15 at 06:16
  • 1
    @AbhishekPandey: The disadvantage of above two implementations: one have to add `beforeSelectRow` and `onSelectAll` to prevent selection (like in [the old answer](http://stackoverflow.com/a/5260847/315935)). Thus the way with disabling the row is the preferred way. – Oleg Nov 25 '15 at 06:32
  • oleg : Ok, Thanks for the help and reply – Abb Nov 25 '15 at 08:32