Select right value for select when using select2 with jqGrid

后端 未结 2 1474
情书的邮戳
情书的邮戳 2021-01-16 12:41

I\'m using select2 with jqGrid. For \"select\" elemets I do folowing:

{label:\"Teacher\",name:\"teacher\",index:\"teacher\",editable:true,edittype:\"select\"         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 13:15

    It seems to me that the reason of the problem very easy. You use selectFilled in the wrong way. The most callbacks introduced in free jqGrid have one parameter options which have different properties which can be used by the callback. In the way one can write short code without declaring unused parameters and one can extend the list of option of the callback later without breaking compatibility to the previous versions. In other words you can use select2 in the following way for example:

    selectFilled: function (options) {
        $(options.elem).select2({
            dropdownCssClass: "ui-widget ui-jqdialog",
            width: "100%"
        });
    }
    

    The usage of dropdownCssClass fixes the font size and the style of the dropdown created by select2.

    The demo demonstrates the above code. It uses

    edittype: "select", editoptions: {
        dataUrl: "ShippedVia.htm",
        defaultValue: "DHL",
        selectFilled: function (options) {
            $(options.elem).select2({
                dropdownCssClass: "ui-widget ui-jqdialog",
                width: "100%"
            });
        }
    }
    

    where the data loaded from dataUrl has the following HTML fragment

    
    

    The demo works with both inline editing and form editing. The GUI looks like on the pictures below:

    and

提交回复
热议问题