2

I need to get the cell object (not the cell value) from my customer formatter.

What I am trying to do is to place one of my superfish menus next to the cell so I need to access the cell from jQuery.

At the moment I have derived the row Index and column Index from inside the formatter but I need to access the current cell from Jquery.

After further analysis to the generated code, it seems there's no id set for the table cell in jqGrid.

I feel like I should be able to do this using the RowObject parameter but all my efforts failed so far.

Below is my simplified code:

function ViewColumnFormatter(cellvalue, options, rowObject) {
    if (cellvalue == undefined || cellvalue == "")
        return "";

    if (options.colModel.commandCount > 1) {
        // Here, I need to access the cellObject...
        // I know about options.rowId and options.pos
        // What I need is to access the cell "object"
    }
}

How can I access the cell object from within the custom formatter?

Luís Cruz
  • 14,264
  • 16
  • 68
  • 94
Menol
  • 1,112
  • 19
  • 33

1 Answers1

0

You can inject any HTML using custom formatter.

If you use custom formatter together with xml datatype the rowObject parameter will be object represented the DOM element of the corresponding row of the XML input. The type of rowObject is IXMLDOMElement. To find the contain of the corresponding child element which correspond of the column 'myColumn' you can use for example

$(rowObject).find('myColumn')

If you use loadonce:true jqGrid parameter, then at the first load the rowObject parameter will be DOM element and at later as the named JavaScript object and the data which you need will be accessed as rowObject.myColumn

See Question

Community
  • 1
  • 1
Deepak
  • 186
  • 3
  • Thanks for the answer, but this can't help me because I only have the row index and column index to refer to the cell. can you please explain how I can find the value for 'myColumn' ? Thanks again... – Menol Aug 16 '13 at 09:24
  • I suggest you to use jQuery.isArray(rowObject) as a quick and effective way to determine whether you should access rowObject per integer index rowObject[3] (if you access remote data) or per named property rowObject.myColumn – Deepak Aug 16 '13 at 10:06