开发者

Accessing rowObejct inside custom_element

开发者 https://www.devze.com 2023-03-18 11:47 出处:网络
According to the documentation it\'s possible to write own function for creating custom input element for cell:

According to the documentation it's possible to write own function for creating custom input element for cell:

<script>
function myelem (value, options) {
  var el = document.createElement("input");
  el.type="text";
  el.value = value;
  return el;
}

function myvalue(elem, operation, value) {
    if(operation === 'get') {
       return $(elem).find("input").val();
    } else if(operation === 'set') {
       $('input',elem).val(value);
    }
}
jQuery("#grid_id").jqGrid({
...
   colModel: [ 
      ... 
      {name:'price', ..., editable:true, edittype:'custom', editoptions:    {custom_element: myelem, custom_value:myvalue} },
      ...
   ]
...
});
</script>

Is it possible to access rowObject from custom_element (myelem) function, because I have to开发者_StackOverflow create different controls (input, select) depending on rowObject data (e.g rowObject.type)?


You are right, it could be practical to have rowObject parameter which not exist. As a workaround I could suggest to use options parameter of the custom_element (in your example myelem) function.

If custom control for editing will be created the object having id and name properties will be used as the options parameter. The id will be id of the new created elements and the name is the value from the name property of colModel of the corresponding column. You can use the fact that the id value will be constructed from the rowid and it will be appended by underscore and the column name (the name property). So the options.id is rowid + '_' + options.name and you can easy get the value of current rowid. Then using getRowData you can get rowObject, which you need. Instead of getRowData you can use getCell of cause.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号