I have a field / column in my jqGrid that gets its value from the FlexBox control (http://www.fairwaytech.com/flexbox). I use the form to edit / add data to the grid locally, and then I submit the complete data as a whole to the server. I implemented the FlexBox control in my form as a user control containing functions for creating controls, getting values, etc. (Editoptions: {custom_element: myCustomElem, custom_value: myCustomValue, ...)
So, I have a code / value pair (as in the usual HTML selection), and in the grid I want to show the value, but I want to send the code to the server. When I download data from the server, I get code / value pairs.
So, I tried to write my own formatting / unformatter, only to find out that the formatter seems to irreversibly modify the original data! So, as soon as I get my value back from formatting (i.e. when displaying data in a grid cell), the code will be lost! And thus, when unformatter is called (i.e. when sending data to the server), the code no longer exists!
The grid is set with the following parameters:
cellsubmit: 'clientArray', datatype: 'clientSide', editurl: '/dummy'
In my navGrid options for adding / editing, I have a beforeShowForm function that builds a FlexBox control. The FlexBox control has 2 fields, one normal input and one hidden. The hidden one contains the code, and the normal value is / shows the value.
The myCustomValue function looks like this:
function myCustomValue (elem, action, val) {
var value = val, code = val;
if(action == 'get') {
code = $('input[id="' + $(elem).attr('id') + '_div_hidden"]').val();
value = $('input[id="' + $(elem).attr('id') + '_div_input"]').val();
}
else {
$('input[id="' + $(elem).attr('id') + '_div_input"]').val(value);
}
return (code == value ? value : code + '||' + value);
}
, , '||' ( ).
:
function myFormatter(cellvalue, options, rowdata, action) {
if(cellvalue == '')
return cellvalue;
var codeValuePair = cellvalue.split('||');
if(codeValuePair && codeValuePair.length > 1)
return '<span class="md-flexbox-code" style="display:none;">' + codeValuePair[0] + '</span>' + codeValuePair[1];
else
return cellvalue;
}
unformatter , , , .
- ? , !