0

I use setColProp function to set formatter property:

existingGrid.setColProp('SelectAction', {
    formatter: function() {
        return "<span class='ui-icon ui-icon-plus' style='display:inline-block' title='Add item'></span>";
    }
});

but debugger shows that formatter is added as function of length 0? Wht does this happen?

Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137

1 Answers1

2

Yes, one can use setColProp to change formatter. It's important only to understand when the formatter will be used. The most common case of the formatter usage is filling of the grid with the data. So if you want for example load the data from the server and change the formatter based on the server response you have to use beforeProcessing callback. If you would try to change formatter inside of loadComplete callback for example the changes will be not used during the current processing of the data.

The old answer provide an example of dynamical setting of formatter.

By the way you can extend $.fn.fmatter to define new custom formatter which can you use in the same as predefined formatters. See formatter: "dynamicLink" or formatter: "checkboxFontAwesome4" as examples.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @voroninp: Sorry, but I see no sense to use `tableToGrid`. It's very old and very slow. Moreover setting of formatter *after* creating and filling the grid (by `tableToGrid`) don't change anything. One have to call reloadGrid to make the changing working. One can use `datatype: "local", data: arrayWithData` in the most cases instead of usage `tableToGrid`. What kind of information are inside of the table which you convert? An example could clear everything. – Oleg Jan 09 '14 at 14:55
  • Well. it's not my code indeed. I just need to change it a little. Full table is generated in Razor view and then tableToGrid is called. – Pavel Voronin Jan 09 '14 at 15:01
  • @voroninp: I can repeat that it's a wrong way. You need provide *data* instead of view. Grid will hold the data. One can use paging, sorting, filtering (searching) in the grid based on the data. The data can be sorted correspond to the *type of data* (like 1 2 11 instead of 1 11 2) and so on. – Oleg Jan 09 '14 at 15:11
  • Anyway I add formatter to the 'service' column thus adding Add button to each row. By the way can you give me the link to example with local data? – Pavel Voronin Jan 09 '14 at 17:03
  • @voroninp: [the demo](http://www.ok-soft-gmbh.com/jqGrid/ViewFormOnDoubleClick1.htm) is one from many example of usage `datatype: "local", data: arrayWithData`. – Oleg Jan 09 '14 at 17:59