crimsoniris
crimsoniris

Reputation: 84

Get column name of selected row jqGrid

Is there a way for me to get the column name of the selected row on jqGrid? For example, on the fiddle: http://jsfiddle.net/5B2Wh/43/

If I clicked on the cell with the content "Merge C", it will return "Client" which is the column name that it is under.

I tried using the code below, but it only sends undefined.

var cm = jQuery("#scrgrid").jqGrid("getGridParam", "colModel");
alert(cm.name);

Upvotes: 0

Views: 17023

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

do:

...onCellSelect: function(id,cellidx,cellvalue) {  
    var cm = jQuery("#list").jqGrid("getGridParam", "colModel");
    var colNameAttr = cm[cellidx];
    console.log(colNameAttr.name); //gives column name
}
...

Upvotes: 0

Barmar
Barmar

Reputation: 780724

colModel is an array, you have to select the relevant column from it.

$("#scrgrid").jqGrid({
    ...
    onCellSelect: function(row, col, content, event) {
        var cm = jQuery("#scrgrid").jqGrid("getGridParam", "colModel");
        alert(cm[col].name);
    }
});

However, this doesn't work in your grid because you have editing enabled, which disables the ability to select cells.

Upvotes: 1

Related Questions