Is there any way to pass parameters to the column's "formatter" option function from MVC?
I need to use regional settings, so I can't use the built-in format option because it uses en-US settings only. So, I'm using the formatter option to format my fields with regional settings, but I'd like to be able to specify the number of decimal places allowed in my "toRegionalDecimalString" function, for example.
Hi Josh,I'm afraid that the formatter function is called by the igGrid with just one parameter, so even if you have a formatter function with 2, 3 or more input parameters, they will not be honored by the function call.(it doesn't matter if you configure the grid via JavaScript or via the MVC wrapper)So alternatively to a secondary input parameter, you can have a global JS variable which you can take into account in the body of the formatter function.However, the good news is we do ship regional settings alongside with localization settings for our jQuery controls :).The point is that these regional settings aren't well documented (a flaw which will be taken care of in the next volume release's documentation), but you can still use them.They're located in this folder: C:\Program Files (x86)\Infragistics\NetAdvantage 2012.1\jQuery\js\modules\i18n\regionalYou can pick your region of choice's JS file and add a reference to it in order to receive the regional settings described in it.The only trick is that you need to reference such a regional JS file after the reference to the infragistics.util.js file.I've attached an HTML sample page which demonstrates the Finnish regional settings being applied to the igGrid's column (in this case: a number and date columns).Let us know if you need any further assistance with "regionalizing" our jQuery controls. Cheers,Borislav
Hi Borislav,again on this topic: unfortunately column formatters only have one parameter, which is the current value of the cell. Is it possible, at least, to get informations about the current row and column? I was thinking at something similar to knockout's event parameters, "data" and "event".
I would like to render a numeric column as an image column, so I customized column options with a template and a formatter, as suggested here.I need to obtain an image source not only depending on the current value, but also depending on something like a custom matrix, which is different for each column: value1>imageA, value2>imageB, etc.
Could you please help me implementing such a feature on my igGrid?Thank you, Maria
Hello Maria,
This might be the case if you are using an older version but in recent ones the formatter receives both the value and the whole record (as shown in the code snippet here). The template is also executed against the whole record so you can reference other properties from inside.
Best regards,
Stamen Stoychev
Thanks for your reply: I'm currently using Ignite 16.2 and I'm seeing now that also this version ships the additional 'record' parameter.But I also need to know on which column the function is being invoked: is there a workaround to obtain that information?
Thanks again.
Unfortunately, the grid doesn't pass that. If you have a single formatter function for multiple columns you could assign (as their formatters) anonymous functions that call the actual formatter one with the additional argument of that column's key.
Perfect, thanks a lot. I didn't think this could be done!
Here is the working code:
if (column.type == 'image') { option.dataType = "object"; option.template = "<img width='16' height='16' src=${" + column.propertyName + "}></img>"; option.formatter = function (value, record) { return getImageSource(value, "myCustomParam", "myOtherParam"); }; }
Regards, Maria