0

I am trying to get specific columns value on dubble click on row.

I have tried solution from these two post but not success:

  1. jqGrid HOWTO: Get the value of specific cell upon double click on row

  2. jqGrid gridComplete:- getRowData - get row cell value from array

I have following code:

jQuery("#list2").jqGrid({
    url:'<%=request.getContextPath()%>/peripherals/list',
    datatype: "json",
    mtype:"POST",
    colNames:['Id', 'Name', 'Gateway', 'Type', 'Status', 'Created On', 'status_id'],
    colModel:[{name:'id',index:'id', align:"right",hidden:true},        
                {name:'Name',index:'Name', align:"left", shrinkToFit: true},
                {name:'BoxName',index:'BoxName', align:"left", shrinkToFit: true},
                {name:'Type',index:'Type', align:"left", shrinkToFit: true},
                {name:'Status',index:'Status', align:"left", shrinkToFit: true},
                {name:'Time_Tag',index:'Time_Tag', align:"left", shrinkToFit: true},
                {name:'status_id',index:'status_id', align:"right",hidden:true}
    ],

    height: 500,
    rowNum:50,
    rowList:[10,20,30,50,75,100,500,1000],
    pager: '#pager2',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"",
    ondblClickRow: function(id) {
        var rowData = jQuery(this).getRowData(id);

        var selRow = jQuery("#list2").jqGrid('getGridParam','selarrrow');
        var data = jQuery(this).jqGrid('getRowData',selRow);
        alert("Type -> "+data.Type + ", Name -> " + data.name); // gives undefined instead of values

        if(rowData['status_id'] == 7){
            jQuery(".alert").show();
            jQuery(".alert").html("<strong>Warning!</strong> "+rowData['Status']+" for "+rowData['Name']);  
        } else {
            window.location ="<%=request.getContextPath()%>/peripherals/detail/" + id;  
        }
    }    
});
Community
  • 1
  • 1
mumair
  • 2,768
  • 30
  • 39

1 Answers1

1

It's not full clear what you need to implement, but the code of ondblClickRow contains some clear errors.

You use the lines

var selRow = jQuery("#list2").jqGrid('getGridParam','selarrrow');
var data = jQuery(this).jqGrid('getRowData',selRow);

which will always assign empty object {} to data because parameter selRow should be the rowid, but you have selRow equal to [] always because selarrrow get the array of rowids of multiselect grid. You don't use multiselect: true option. Thus selarrrow have the value []. If you need to get the rowid of selected row then you should use selrow instead of selarrrow. On the other side you write the code of ondblClickRow callback and so it's better just use id parameter of the callback.

The second important error exist because of usage rowData['Status'] inctead of rowData['status_id'] (or better rowData.status_id).

If I correctly understand what you want to do then you should rewrite the implementation of ondblClickRow to the following

ondblClickRow: function (rowid) {
    var rowData = jQuery(this).getRowData(rowid);

    if (rowData.status_id === "7") {
        jQuery(".alert")
            .html("<strong>Warning!</strong> " + rowData.status_id +
                  " for " + rowData.Name)
            .show();  
    } else {
        location = "<%=request.getContextPath()%>/peripherals/detail/" + rowid;  
    }
}
Oleg
  • 220,925
  • 34
  • 403
  • 798