使用表单编辑时的jqgrid multiselect下拉列表 [英] jqgrid multiselect dropdown when using form edit
问题描述
这是我的多选下拉列表中的代码.它按预期运行,但我希望在编辑模式下进行一些修改.
This is the code of my multiselect dropdown column. It is working as I expected but I want some modification on edit mode.
{
name: 'SubjectId',
index: 'SubjectId',
align: 'center',
hidden: true,
viewable: true,
editrules: { edithidden: true },
editable: true,
formatter: 'select',
editable: true,
edittype: 'select',
editoptions: {
multiselect: true,
dataUrl: '@Url.Action("getAllSubjects", "Subject")',
//buildSelect: function (data) {
//var retValue = $.parseJSON(data);
buildSelect: function (data) {
var response, s = '<select>', i;
response = jQuery.parseJSON(data);
// s += '<option value="0">--Select Subject--</option>';
if (response && response.length) {
$.each(response, function (i) {
s += '<option value="' + this.Id + '">' + this.SubjectName + '</option>';
});
}
return s + '</select>';
},
dataInit: function (elem) {
setTimeout(function () {
$('#SubjectId').multiselect();
}, 5);
},
multiple: true,
}
},
但是在编辑模式下,我想使multiselect设置为false.该怎么做.我不知道该怎么做.
But on edit mode I want to make multiselect false.How can do it.I don't understand how to do it.
推荐答案
首先,您的代码输入错误:应该使用dataInit
而不是ddataInit
.
First of all your code has typing error: one should use dataInit
instead of ddataInit
.
如果只需要在添加"表单中使用"multiselect
"而不是在编辑"表单中使用,我建议您最好不要使用multiselect: true
和dataInit
.取而代之的是,您可以使用beforeShowForm
回调(请参见文档).在回调内部,您可以设置multiple
属性(请参见 jQuery.attr )并调用$('#SubjectId').multiselect();
.如果只为添加表单指定这样的beforeShowForm
回调,则应具有所需的行为.两种情况下,您都应同时使用recreateForm: true
属性添加和编辑表单.
If you need to use multiselect
only in Add form and not in Edit form I would recommend you better don't use multiselect: true
and dataInit
. Instead of that you can use beforeShowForm
callback (see the documentation). Inside of the callback you can set multiple
attribute (see jQuery.attr) and call $('#SubjectId').multiselect();
. If you would specify such beforeShowForm
callback only for the Add form you should have the behavior which you require. Of case you should use recreateForm: true
property for both Add and Edit forms.
这篇关于使用表单编辑时的jqgrid multiselect下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!