Reputation: 1946
I have a jqGrid where the formatter function for the colModel must be defined as a string
{name:'FileSize', index:'FileSize', width:90, editable: true,
formatter: 'fileSizeFormatter'}
I can't use the following where the formatter function is not a string because I build the colmodels on the server side in C#. If I could use the non string formatter Defining unformatter would be a solution as shown in Here
{name:'FileSize', index:'FileSize', width:90, editable: true,
formatter: fileSizeFormatter}
And here is the fileSizeFormatter I needed to use fn.fmatter because my formatter is passed as a string and the code assumes it is one of the predefined one's lile "select", "currency"...etc
$.fn.fmatter.fileSizeFormatter = function (cellval, options) {
var fileUnit = "B";
if (cellval) {
var fileUnit;
var iKBFileSize;
if (cellval < 1024) {
iKBFileSize = cellval;
} else {
iKBFileSize = cellval / 1024;
fileUnit = "KB";
}
var result = iKBFileSize.toFixed(1) + fileUnit;
return result;
}
return cellval + fileUnit;
};
So the question is how can I define unformatter for a formatter which is passed as a string. When I do grid.getrowdata or edit the cell my unformatter is not being used. It is getting me the data with the file unit.
$.unformat.fileSizeFormatter = function (cellvalue, options, cell) {
return $('input', cellval).is(":checked") ? true : false;
};
Upvotes: 1
Views: 174
Reputation: 222017
You should define unformatter in a little another way:
$.fn.fmatter.fileSizeFormatter.unformat = function (cellValue, options, elem) {
return $(elem).find('input').is(":checked") ? true : false;
}
You should define unformatter of cause after defining the formatter ($.fn.fmatter.fileSizeFormatter
).
Upvotes: 1