'How to get row ID by row Data in jqgrid (Not by selected row)

I want to get the row id by content of cell in jqGrid (Not by selected row).

Example pic

By PRODUCTID, I can get the row id.

e.g. for PRODUCTID is ABCD, I can get 2.

The column PRODUCTID is unique.

Please give me some advices.

Thanks a lot.

My code sample:

$("#project_jqGrid").jqGrid({
    url: 'project/projectQuery.php',
    mtype: "POST",
    datatype: "json",
    page: 1,
    colModel: [
        {   label : "PRODUCTLINE",
            //sorttype: 'integer',
            name: 'PRODUCTLINE', 
            //key: true, 
            width: 100,
            editable:true,
            editoptions:{readonly:'readonly'}
        },
        {   label : "GPOWNER",
            //sorttype: 'integer',
            name: 'GPOWNER', 
            //key: true, 
            width: 150,
            editable:true,
            editoptions:{readonly:'readonly'}
        },
        {   label : "PRODUCTID",
            //sorttype: 'integer',
            name: 'PRODUCTID', 
            key: true, 
            width: 100,
            editable:true,
            editoptions:{readonly:'readonly'}
        },
    ],
    loadComplete: function() {

        $.ajax({
           dataType: 'json',
           url : "project/projectDifferQuery.php", // your php file
           type : "GET", // type of the HTTP request
           success : function(data){

              // I can get PRODUCTID from mysql database
              // I want to get rowid to change cells color by PRODUCTID
              // ........

              // Change Cells Color(I need to get '5' by position of PRODUCTID)
              //$('#project_jqGrid').jqGrid('setCell',5,"GPOWNER","",{'background-color':'#FF4545'});

           }
        });

    },
    loadonce: true,
    viewrecords: true,
    width: 'auto',
    height: 'auto',
    rowNum: 20,
    pager: "#project_jqGridPager"//,

});

> Versions: - jqGrid 5.1.1



Solution 1:[1]

It is little difficult to understand what you want to get - I think you mean rowIndex, so here are some methods which can help.

Methods

getGridRowById( string rowid)

Return the row with id = rowid as document object

getInd(string rowid, [boolean rowcontent])

Returns the index of the row in the grid table specified by grid id row - rowid. If rowcontent is set to true it returns the row document object

If you have the row as document object you can get the index and id. Suppose the rowdata is the document row, then

rowdata.rowIndex is the index

rowdata.id is the id

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tony Tomov