jqGrid - format ratio field as percent value

陌路散爱 提交于 2019-11-27 05:13:31

You can skip the unformatter in favour of custom edit type, just use this in your colModel:

{ ..., edittype: 'custom', editoptions: { custom_element: function(value, options) { return $('<input type="text" value="' + value + '"/>'); }, custom_value: function(element){ return parseFloat(element.val())/100; }  }}
Oleg

To have full support of your custom type of data like 0.0 to 1.0 displayed as percent value inclusive editing and searching you have to implements:

  1. implement formatter to display the data in the grid in the custom way.
  2. implement unformat to allow access to the data from its "visual representation". The method will be used by jqGrid in some situations (for example during initializing phase of form editing).
  3. define sorttype, which could be some compatible type of data like 'number' or your custom sorting function.
  4. use edittype: 'custom' and implement custom_element and custom_value of editoptions (see the documentation).
  5. use stype: 'custom' and implement custom_element and custom_value of editoptions.

In some situations one from the steps could be skipped, but in the common case you have to think about implementation all of the steps. You should verify which steps from above are still not implemented in your solution.

The demo is the modification of the demo from the old answer and another answer. The demo is not oriented on your direct question. It shows just why and how one can full implement custom control in jqGrid. The functionally of form editing works not full in the demo only because of no server part implemented. If needed one could use the approach from the answer which shows how local form editing can be implemented in jqGrid. I don't wanted to make the code more complex as requiret to show the main purpose of the demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!