jqGrid add item checkbox field defaulted to checked

后端 未结 2 1479
青春惊慌失措
青春惊慌失措 2021-01-15 06:43

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

2条回答
  •  有刺的猬
    2021-01-15 07:12

    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".

提交回复
热议问题