开发者

jqgrid checkbox column- editoptions gets screwed-up when in form editing mode

开发者 https://www.devze.com 2023-03-07 10:58 出处:网络
I defined inline-editing for my grid, which contains some checkbox columns, and it works fine. I set the \'navGrid\' option to edit: true, and I get the nice pencil icon and a form is opened when I pr

I defined inline-editing for my grid, which contains some checkbox columns, and it works fine.

I set the 'navGrid' option to edit: true, and I get the nice pencil icon and a form is opened when I press it.

the problem is- I define the value property of the column like so: value: 'true:false' , which works fine for in-line editing (the generated input element:

<input type="checkbox" disabled="disabled" offval="no" value="false"> ),

but in form edit mode, the generated input is:

<input id="isadministrator" class="FormElement" type="checkbox" checked="" value="true:false" offval="false" name="isadministrator" role="checkbox">

which causes the checked value to be posted to server as 'true:false'.

any ideas? attached is my whole grid code:

$("#grid").jqGrid({
        url: 'SampleScriptService.asmx/GetGridData',
        datatype: 'json',
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        serializeGridData: function (postData) {
            //with ASP.Net services, all parameters must be set in the post request.
            //so here we make sure that all the parameters that the web service expects are prensent. if not- we create them with null value.
            if (!postData.username) {
                postData.username = null;
            }
            if (!postData.fullname) {
                postData.fullname = null;
            }

            if (!postData.isadministrator) {
                postData.isadministrator = null;
            }
            return JSON.stringify(postData);
        },
        mtype: "POST",
        jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", records: "d.records", total: "d.total" },
        colNames: ['Username', 'Full Name', 'Administrator?', 'Password'],
        colModel: [
            { name: 'username', key: true, index: 'username', jsonmap: 'Username', 
                editable:false , edittype:'text'
            },
            { name: 'fullname', index: 'fullname', /* width: 90,*/
                editable:true, edittype:'text',
                jsonmap: 'FullName' },
            { name: 'isadministrator', index: 'isadministrator', formatter: 'checkbox', sortable: false,
                editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' },
                stype: 'select', searchoptions: { value: 'none:All;true:Yes;false:No' }
                /*, width: 80*/, jsonmap: 'IsAdministrator' },
            { name: 'password', index: 'password'
                /*, width: 150*/,
                editable: true, edittype: 'password',
                formatter: function (cellvalue, options, rowObject) {
  开发者_运维百科                  //never display anything in the password column
                    return '';
                },
                jsonmap: 'Password', search: false }
             ],
        rowNum: 2,
        pager: '#pager',
        viewrecords: true,
        sortname: 'username',
        caption: "Users Management",
        onSelectRow: function (id) {
            if (id && id !== currentlyEditedRowId) {
                jQuery('#grid').restoreRow(currentlyEditedRowId);
                currentlyEditedRowId = id;
            }
            jQuery('#grid').editRow(currentlyEditedRowId, true);
        },
        editurl: "SampleScriptService.asmx/UpdateUser"
    }).jqGrid('navGrid', "#pager", { edit: true, add: true, del: false, search: false })
        //add toolbar searching
    .jqGrid('filterToolbar', {});


not an answer to your question, really but a workaround,

I too was having problems with the checkbox sending 1:0 as the value when checked.

instead i reverted to using a dropdown and that worked ok:

{
            name:'active_mdt',
            index:'active_mdt', 
            width:20, 
            align:"left",
            sortable:true,
            editable:true,
            edittype:"select",
            editoptions: {value:{'1':'Active','0':'Hidden'}},
            search:true,//
            stype:'select',
            searchoptions:{value:{'':'All','1':'Active','0':'Hidden'}}
        }], search : {
             caption: "Search...",
             Find: "Find",
             Reset: "Reset",
             matchText: " match",
             rulesText: " rules"
       },


@Dizzy Bryan High made a suggestion which is a very reasonable workaround.
since I didn't want to give up the checkboxes, I ended up just implementing a JQgridParseBool() method on server side, which handles the wrong value sent.
Yep, it's quite ugly, but I couldn't find any other way around it.

0

精彩评论

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