How to apply column template after jqgrid is created

后端 未结 1 539
夕颜
夕颜 2021-01-24 13:54

Free jqgrid does not allw to apply column template after it is created. I tried

  var newOrderPriceTemplate = {
    align: \"center\",
    formatter: \"showlink\         


        
相关标签:
1条回答
  • 2021-01-24 14:42

    I think that there are misunderstanding how templates works. Template is nothing more as the list of settings which will be used in $.extend to combine some current properties from colModel with another object of template properties.

    I recommend to read the code fragment of the code of free jqGrid. In simplified form the code looks like

    for (iCol = 0; iCol < p.colModel.length; iCol++) {
        p.colModel[iCol] = $.extend(true, {},
            p.cmTemplate,
            p.colModel[iCol].template || {},
            p.colModel[iCol]);
    }
    

    In other words jqGrid combines the values from cmTemplate, template property of the column with the property of colModel. jqGrid does it at the beginning of creating the grid.

    Thus if you have some template (newOrderPriceTemplate for example), which you need to apply after the grid is created, then you need just use $.extend manually to extend (and overwrite) the existing properties:

    var p = $grid.jqGrid("getGridParam");
    
    p.colModel[p.iColByName.Hind] = $.extend(true, {},
        p.colModel[p.iColByName.Hind], // old values
        newOrderPriceTemplate,         // the applied template
        { search: false }              // one more setting to apply
    );
    

    It's important to place new properties after the current settings from p.colModel[p.iColByName.Hind] to be able to overwrite there.

    0 讨论(0)
提交回复
热议问题