前言:用户在Grid里面的操作是一种富客户端的应用,下拉框编辑功能必不可少,目前已经整理出单元格嵌入方式的下拉框,只读下拉框列和可编辑的下拉框插件。在此把大致的开发过程总以总结说明,以飨读者。
1. DropdownList Editor -- 嵌入单元格
1). 绑定外部数据源和Changed事件
var dataSouce = args.grid.$selDropdownlistDatasource;
var changedEvent = args.grid.$selDropdownlistChangedEvent;
2). 初始化方法
$select = this.preRender(args.grid.$selDropdownlistDatasource);
if (changedEvent != null)
$select.change(function () {
changedEvent(this, { "ID": $select.val(), "txt": $select.find('option:selected').text() });
});
$select.appendTo(args.container);
预添加控件:
this.preRender = function (dataSource) {
var option_str = "";
var preSelect = "<SELECT tabIndex='0' class='editor-select'><OPTION value='-1'></OPTION>";
var endSelect = "</SELECT>";
var len = dataSource.length;
if (len > 0 && dataSource[0].txt != undefined) {
for (var i = 0; i < len; i++)
option_str += "<OPTION value='" + dataSource[i].ID + "'>" + dataSource[i].txt + "</OPTION>";
}
else {
for (var i = 0; i < len; i++)
option_str += "<OPTION value='" + dataSource[i].ID + "'>" + dataSource[i].Text + "</OPTION>";
}
var list = preSelect + option_str + endSelect;
return $(list);
}
3). 序列化方法
this.serializeValue = function () {
if ($select.val() != -1) {
ret