3

Is it possible have a format number as link in a cell with jqGrid? with two formatter number and link/showlink

colModel:[
{name:'Balance',index:'Balance',align:'right',formatter: 'showlink', sorttype:"float", summaryType:'sum', formatoptions:{thousandsSeparator:","}},...

Im trying to set Balance as link and still able to sum up with grouping

TIA

aramadhani
  • 53
  • 2
  • 13

1 Answers1

3

Yes, you can!

You can define custom formatter and call the original "number" and "showlink" formatters inside of the your custom formatters.

For example the demo uses

formatter: function (cellValue, options, rowObject, action) {
    return $.fn.fmatter.call(this, "showlink",
        $.fn.fmatter.call(this, "number", cellValue, options, rowObject, action),
        options,
        rowObject,
        action);
},
formatoptions: { decimalSeparator: ",", baseLinkUrl: "http://www.google.com/"}

How you can see I used options of custom formatter as the corresponding parameter of $.fn.fmatter. So one can use mix from options of "number" and "showlink" formatters inside of formatoptions.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg, it would be great to pass a set of formatters, such as `formatter: ['number', 'showlink']`. Is it possible in the future? – Serhii Popov Sep 19 '18 at 12:25
  • @SerhiiPopov: The formatter should return a string. You can construct it any way, in which you need. For example, `var n1 = $.fn.fmatter.call(this, "number", options.rowData.field1, options, rowObject, action), n2 = $.fn.fmatter.call(this, "number", options.rowData.field2, options, rowObject, action);` get the data from two properties/columns (`field1` and `field2`) and then one can use `$.fn.fmatter.call(this, "showlink", n1 + " : " + n2, options, rowObject, action);` create link in the form `n1 + " : " + n2`. How you can use `formatter: ['number', 'showlink']` in such case? – Oleg Sep 19 '18 at 13:02
  • @SerhiiPopov: One can't provide short form (like `formatter: ['number', 'showlink']`) which will be flexible enough. Thus I prefer to describe how one can use an existing formatter (b call of `$.fn.fmatter`) and any developer can build your own custom formatter. – Oleg Sep 19 '18 at 13:04