1

Am working on JQGrid where I am loading the ColName & ColModel Dynamically using this Example jqGrid and dynamic column binding

Everything looks good. Am using Formatter in one of the Columns for Formatter

function UrlFmatter(cellvalue, options, rowObject) {
}

When I write Columns in .JS it looked like this

colmodel :[{ name: 'somenam', formatter: UrlFmatter, width: 95, align: "center", index: 'somenam'}]

As am loading Dynamically now it is not working as the function is not called i suppose.

I thought formatter: "UrlFmatter" it is loaded like this and making it a string. How do i make this function call ?

Or is there some better way I can handle these scenarios ?

Community
  • 1
  • 1
user2067567
  • 3,695
  • 15
  • 49
  • 77
  • `formatter: UrlFmatter` is the right way. Where are you defining the `function UrlFmatter()` – Ajo Koshy Mar 19 '13 at 05:44
  • yes that is the right way.But wen coming in json "" appended. if i remove that it ll call that function or anyother way – user2067567 Mar 19 '13 at 05:46
  • See this [link](http://stackoverflow.com/questions/13792329/how-to-pass-a-function-name-via-json-and-call-it-in-javascript-jquery) for getting to know how to call function name that occurs in json data – Ajo Koshy Mar 19 '13 at 06:13

1 Answers1

1

It seems exact duplicate of your old question. As I answered before (see here) you should replace definition of UrlFmatter from

function UrlFmatter(cellvalue, options, rowObject) {
    return "<a href='DetailResult?airportname=" + options.rowId + "' >" +
        cellvalue + "</a>";
}

to

(function ($) {
    "use strict";
    $.extend($.fn.fmatter, {
        urlFmatter: function (cellValue, options) {
            return "<a href='DetailResult?airportname=" + options.rowId + "' >" +
                cellvalue + "</a>";
        }
    });
}(jQuery));

You should include the above code directly after jquery.jqGrid.min.js (or after jquery.jqGrid.src.js). After that you can modify

{ name: 'somenam', formatter: UrlFmatter, width: 95, align: "center", index: 'somenam'}

to

{ name: 'somenam', formatter: "urlFmatter", width: 95, align: "center"}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798