1 多选下拉框加载时设置默认选中值
1.1 setValues+勾选选中行的复选框
unction BindMultiListCode(objId,comboxData,values){
$('#' + objId).combobox({
data: comboxData,
valueField: 'Code',
textField: 'CodeName',
panelHeight: 'auto',
editable: false,
showblank: true,
multiple: true,
formatter: function (row) {
var opts = $(this).combobox('options');
return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
},
onLoadSuccess: function (data) {
//多选下拉框加载成功后设置默认选中值
$('#' + objId).combobox("setValues", values);
for (var i = 0; i < values.length; i++) {
var value = values[i];
var children = $(target).combobox("panel").children();
$.each(children, function (index, obj) {
if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
}
},
onSelect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
},
onUnselect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = false;
}
});
}
});
}
1.2 select
unction BindMultiListCode(objId,comboxData,values){
$('#' + objId).combobox({
data: comboxData,
valueField: 'Code',
textField: 'CodeName',
panelHeight: 'auto',
editable: false,
showblank: true,
multiple: true,
formatter: function (row) {
var opts = $(this).combobox('options');
return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
},
onLoadSuccess: function (data) {
//多选下拉框加载成功后设置默认选中值
$('#' + objId).combobox("setValues", values);
for (var i = 0; i < values.length; i++) {
var value = values[i];
$('#' + objId).combobox('select', value.toString());
}
},
onSelect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
},
onUnselect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = false;
}
});
}
});
}
2 多选下拉框加载时设置默认选中前几项
2.1 setValues+勾选选中行的复选框
function BindMultiListCode(objId,comboxData,selectCount){
var i = 1;
var values = [];
$('#' + objId).combobox({
data: comboxData,
valueField: 'Code',
textField: 'CodeName',
panelHeight: 'auto',
editable: false,
showblank: true,
multiple: true,
formatter: function (row) {
var opts = $(this).combobox('options');
//获取前几项
if (i++ <= selectCount) {
values.push(row[opts.valueField]);
}
return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
},
onLoadSuccess: function (data) {
//多选下拉框加载成功后设置默认选中值
$('#' + objId).combobox("setValues", values);
for (var i = 0; i < values.length; i++) {
var value = values[i];
var children = $(target).combobox("panel").children();
$.each(children, function (index, obj) {
if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
}
},
onSelect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
},
onUnselect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = false;
}
});
}
});
}
2.2 select
function BindMultiListCode(objId,comboxData,selectCount){
var i = 1;
var values = [];
$('#' + objId).combobox({
data: comboxData,
valueField: 'Code',
textField: 'CodeName',
panelHeight: 'auto',
editable: false,
showblank: true,
multiple: true,
formatter: function (row) {
var opts = $(this).combobox('options');
//获取前几项
if (i++ <= selectCount) {
values.push(row[opts.valueField]);
}
return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
},
onLoadSuccess: function (data) {
//多选下拉框加载成功后设置默认选中值
$('#' + objId).combobox("setValues", values);
for (var i = 0; i < values.length; i++) {
var value = values[i];
$('#' + objId).combobox('select', value.toString());
}
},
onSelect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = true;
}
});
},
onUnselect: function (row) {
var opts = $(this).combobox("options");
var objCom = null;
var children = $(this).combobox("panel").children();
$.each(children, function (index, obj) {
if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
obj.children[0].checked = false;
}
});
}
});
}
还没有评论,来说两句吧...