troubleshooting Question

jQuery jqGrid cannot get custom formatter radio buttons value

Avatar of Sailing_12
Sailing_12 asked on
jQueryJavaScriptScripting Languages
3 Comments1 Solution1651 ViewsLast Modified:
I've created a custom formatter to render a pair of radio buttons for a bool field in jqGrid using the radioButtonFormatter function below.

Also have radio button markup in the myelem function below which is the editoptions:custom_element call to retain the formatting when user clicks in the cell (but not directly on a radio button).

This much works, but if user then clicks out of the cell, the myvalue function which is wired to editoptions:custom_value does not return the value, in fact the 'value' parameter being passed in with 'elem' and 'operation' is empty if I alert it out... So we end up having values reset to 0,no when they should'nt be.

Cannot figure out why the value is not available in the myvalue function.


	
								
case 6: //Two Options

elType = "custom";
format = radioButtonFormatter;
objColumn = { Type: rData.new_Type.Value, name: rData.new_FieldName, width: rData.new_Width, align: align, editable: editable, bulkeditable: rData.new_bulkeditable, edittype: elType,editoptions:{custom_element: myelem, custom_value: myvalue}, formatter: format };

	function myelem (value, options) {
		  
		  var elemStr = '';
		  
		  var _position = value.indexOf('checked=""') + 18;  
		  var _value = value.substr(_position, 1);
		  		  
		  if (_value == '0'){

				elemStr = '<div class="radioButtons">' + 
								'<input type="radio" name="' + options.id + '" value="0" checked />Inelg ' + 
								'<input type="radio" name="' + options.id + '" value="1" />Elg' + 
							'</div>';		  
		  }
		  else if (_value == '1'){
				elemStr = '<div class="radioButtons">' + 
								'<input type="radio" name="' + options.id + '" value="0" />Inelg ' + 
								'<input type="radio" name="' + options.id + '" value="1" checked />Elg' + 
							'</div>';			  
		  }
		  		  
          // return DOM element from jQuery object
          return $(elemStr)[0];

	}
		
	function myvalue(elem, operation, value) {						
		if(operation === 'get') {
		   alert(value);
		   return $(elem).val();
		} else if(operation === 'set') {
		   $('input',elem).val(value);
		}
	}	

    function radioButtonFormatter(cellvalue, options, rowObject) {

        var radioMarkup = "";
        var dynamicName = options.colModel.name + '_' + options.rowId;
        var disabled = "";

        if (options.colModel.editable == false) {
            disabled = 'disabled';
        }

            if (cellvalue == true) {
                radioMarkup = '<div class="radioButtons"><input type="radio" name="' + dynamicName + '" value="0" onclick="cancelEdit(\'' + options.rowId + '\'); onCellExit(' + options.rowId + ', \'' + options.colModel.name + '\',0 , ' + options.rowId + ', ' + options.pos + ' )" ' + disabled + '>Inelg&nbsp;&nbsp;<input type="radio" name="' + dynamicName + '" value="1" onclick="cancelEdit(\'' + options.rowId + '\'); onCellExit(' + options.rowId + ', \'' + options.colModel.name + '\',1 , ' + options.rowId + ', ' + options.pos + ' )" checked ' + disabled + '>Elg</div>';
            }
            else {
                radioMarkup = '<div class="radioButtons"><input type="radio" name="' + dynamicName + '" value="0" onclick="cancelEdit(\'' + options.rowIdd + '\'); onCellExit(' + options.rowId + ', \'' + options.colModel.name + '\',0 , ' + options.rowId + ', ' + options.pos + ' )" checked ' + disabled + '>Inelg&nbsp;&nbsp;<input type="radio" name="' + dynamicName + '" onclick="cancelEdit(\'' + options.rowId + '\'); onCellExit(' + options.rowId + ', \'' + options.colModel.name + '\',1 , ' + options.rowId + ', ' + options.pos + ' )" value="1" ' + disabled + '>Elg</div>';
            }

        return radioMarkup

    }
ASKER CERTIFIED SOLUTION
Sailing_12Pirate

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros