jqGrid add item checkbox field defaulted to checked

旧时模样 提交于 2019-12-30 10:59:14

问题


Here's a simple question. I have a jqGrid that's working great but I want set the default value for a checkbox to checked when user adds a new item. Here's a snippet of code:

{name: "Active", index: "active", width: 80, align: "center", sortable: false,
 editable: true, edittype: "checkbox", editoptions: {value: "Yes:No"}}

I don't see anything in the documentation:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules


回答1:


You can use

editoptions: {value: "Yes:No", defaultValue: "Yes"}

(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editoptions).

By the way, I personally use always the formatter: "checkbox" for columns like you have. Moreover

stype: "select", searchoptions: { value: "1:Yes;0:No" }

can also be helpful if you allow to search for values from the column.

UPDATED: Free jqGrid 4.13.6 (currently 4.13.6-pre, which one can get from GitHub) supports new stype: "checkbox". One can use, for example

stype: "checkbox", searchoptions: { sopt: ["eq"], value: "true:false" }

to have 3-state checkbox in the filter toolbar and 2-state checkbox in the Searching Dialog. The above searchoptions.value value means that the checked box corresponds the value "true" und unchecked box the value "false".




回答2:


I have used this, it worked.

 editoptions: {value: "true:false", defaultValue: "true"}


来源:https://stackoverflow.com/questions/3007483/jqgrid-add-item-checkbox-field-defaulted-to-checked

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