jqgridjqgrid-formatter

How do i return custom formatter in my JQGrid using getGridParam?


This is what I'm trying to do:

var p = this.jqGrid("getGridParam"), cm = p.colModel

I am able to get the colModel but I had certain custom formatters defined in the model which are not getting returned.

{name:'HTML_DEVICE_CNT',index:'HTML_DEVICE_CNT', width:35, align:"center",editable:true, sortable: false,formatter:deviceDetailsPopup,resizable:false,hidden:hiddenDevice},
{name:'edit',index:'edit', width:20, align:"center",editable:true, sortable: false,formatter:contactDetailsPopup,resizable:false},                    

How can I get getGridParam to return the custom formatter also?


Solution

  • The solution depends on the fork of jqGrid, which you use. Free jqGrid contains iColByName parameter, which simplify getting the item of colModel by the name. Thus you can us the code like

    var p = this.jqGrid("getGridParam"), cm = p.colModel, iColByName = p.iColByName;
    var formatter1 = cm[iColByName.HTML_DEVICE_CNT].formatter;
    var formatter2 = cm[iColByName.edit].formatter;
    

    If you have the column name in the variable cmName then you can use

    var formatter3 = cm[iColByName[cmName]].formatter;
    

    If you have to use an old version of jqGrid then you need to make a loop over all items of cm array and compare the name property of every item with the column name, which you look for ("edit" or "HTML_DEVICE_CNT"). See the function getColumnIndexByName from the old answer for example.