Easyui Datagrid 的Combobox 如何动态修改下拉选项,以及值的转换
我是先将下拉选项的值通过datagrid的url查出来了,在每一行的row中
//项目结果选项卡的列表
$('#project_table').datagrid({
width : '100%',
height: '378',
url : 'getSeparationProjectInf',
//title : '待分发条码列表',
striped : true,
nowrap : true,
rownumbers : true,
singleSelect : true,
showHeader : true,
showFooter : false,
loadMsg : '努力展开中...',
scrollbarSize:0,
fitColumns : true,
checkOnSelect : true,
onClickRow: function (rowIndex, rowData) {
//$(this).datagrid('unselectRow', rowIndex);
var _this = this;
if (editIndex != undefined && editIndex != rowIndex) {
//结束行编辑
endEdit(_this,editIndex);
}
$(_this).datagrid('beginEdit', rowIndex);
$("input.datagrid-editable-input").on("keypress",function(e){
if(e.keyCode==13){
endEdit(_this,editIndex);
}
});
editIndex = rowIndex;
},
onBeginEdit: function(index, rowData){ //动态修改检测结果下拉项
var resultDictionaryDetailList = rowData.resultDictionaryDetailList
//监测结果下拉框
var goEditor = $('#project_table').datagrid('getEditor', {
index : index,
field : 'result'
});
$(goEditor.target).combobox({
onLoadSuccess: function () {
if(rowData.result){
$(goEditor.target).combobox('setValue', rowData.result);
}else{
$(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].id);
}
},
onBeforeLoad: function(){ //下拉展开时动态修改options
if(resultDictionaryDetailList.length){
var data = [];
for ( var index in resultDictionaryDetailList) {
var resultDictionaryDetail = resultDictionaryDetailList[index];
data.push({'id': resultDictionaryDetail.id, 'name':resultDictionaryDetail.name});
}
$(goEditor.target).combobox("loadData", data);
}
}
});
},
columns : [[
{
field : 'ck',
checkbox: true
},
{
field : 'projectId',
title : '项目ID',
align : 'center',
sortable : false,
resizable : false,
hidden: true
},
{
field : 'projectName',
title : '项目',
align : 'center',
sortable : false,
resizable : false,
width : 120
},
{
field : 'data',
title : '检测数据',
align : 'center',
sortable : false,
resizable : false,
width : 100,
editor:{
type:'text'
}
},
{
field : 'result',
title : '检测结果',
align : 'center',
sortable : false,
resizable : false,
width : 100,
formatter: function (value, rowData, rowIndex) {
var resultDictionaryDetailList = rowData.resultDictionaryDetailList;
if(!value){
rowData.result = resultDictionaryDetailList[0].id;
value = resultDictionaryDetailList[0].name;
}
console.log("resultDictionaryDetailList.length=="+resultDictionaryDetailList.length);
for (var i = 0; i < resultDictionaryDetailList.length; i++) {
if (resultDictionaryDetailList[i].id == value) {
return resultDictionaryDetailList[i].name;
}
}
return value;
},
editor:{
type:'combobox',
options:{
valueField:'id',
textField:'name',
//method:'get',
//url:'products.json',
//data: resultDictionaryDetailList,
data: [{
productid: '0',
checkResult: '高'
},{
productid: '1',
checkResult: '低'
}],
required:true
}
}
},
{
field : 'remark',
title : '结果备注',
align : 'center',
sortable : false,
resizable : false,
width : 120 ,
editor : {type:"text"}
},
{
field : 'suggestion',
title : '建议内容',
align : 'center',
sortable : false,
resizable : false,
width : 150,
editor:{ type:'text' }
},
{
field : 'explanation',
title : '医学解释',
align : 'center',
sortable : false,
resizable : false,
width : 150,
editor:{ type:'text' }
},
{
field : 'reason',
title : '常见原因',
align : 'center',
sortable : false,
resizable : false,
width : 150,
hidden: true
},
{
field : 'operate',
title : '操作',
align : 'center',
sortable : false,
resizable : false,
width : 80,
formatter: function(value,row,index){
// return '<a href="javascript:void(0);" onclick="cancelDialog(event)">'+value+'</a>';
}
}
]],
data : [
/*{
project : 'ERCC1基因表达',
checkData : '≥3.4%',
checkResult : '高',
resultRemark : 'xxxxx',
advise : '您患2型糖尿病的基因位.....',
medicalExplanation : '合理安排休息,保证充分....',
operate : '删除',
}*/
],
pagination : false,
/*pageSize : 10,
pageList : [10],
pageNumber : 1,*/
pagePosition : 'bottom',
remoteSort : false,
});
具体解析如下:
onBeginEdit是将row中的下拉项数据拿出来并动态加载到Combobox 中,onBeforeLoad很重要,不然执行onLoadSuccess方法的时候,Combobox还没有动态加载下拉选项,导致显示的是值,而不是值对应的名,所以用onBeforeLoad可以先加载Combobox的下拉选项,然后再回填值
onBeginEdit: function(index, rowData){ //动态修改检测结果下拉项
var resultDictionaryDetailList = rowData.resultDictionaryDetailList
//监测结果下拉框
var goEditor = $('#project_table').datagrid('getEditor', {
index : index,
field : 'result'
});
$(goEditor.target).combobox({
onLoadSuccess: function () {
if(rowData.result){
$(goEditor.target).combobox('setValue', rowData.result);
}else{
$(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].id);
}
},
onBeforeLoad: function(){ //下拉展开时动态修改options
//datatype处理统计方法
if(resultDictionaryDetailList.length){
var data = [];
for ( var index in resultDictionaryDetailList) {
var resultDictionaryDetail = resultDictionaryDetailList[index];
data.push({'id': resultDictionaryDetail.id, 'name':resultDictionaryDetail.name});
}
$(goEditor.target).combobox("loadData", data);
}
/* //设置值
if(rowData.result){
$(goEditor.target).combobox('setValue', rowData.result);
}else{
$(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].name);
}*/
}
});
},
formatter是将值转换成对应的name
formatter: function (value, rowData, rowIndex) {
var resultDictionaryDetailList = rowData.resultDictionaryDetailList;
if(!value){
value = resultDictionaryDetailList[0].id;
rowData.result = value;
}
for (var i = 0; i < resultDictionaryDetailList.length; i++) {
if (resultDictionaryDetailList[i].id == value) {
return resultDictionaryDetailList[i].name;
}
}
return value;
},
Easyui Datagrid 的Combobox 如何动态修改下拉选项,以及值的转换的更多相关文章
- jquery 动态添加下拉框 需要增加 煊染 selectmenu("refresh");
若通过js动态选择下拉框的值必须刷新下拉框,例如:var selArray = $("select#sel");selArray[0].selectedIndex = 1;selA ...
- Easyui datagrid combobox输入框下拉(取消)选值和编辑已选值处理
datagrid combobox输入框下拉(取消)选值和编辑已选值处理 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求场景 如下,在datagri ...
- 通通WPF随笔(1)——基于lucene.NET让ComboBox拥有强大的下拉联想功能
原文:通通WPF随笔(1)--基于lucene.NET让ComboBox拥有强大的下拉联想功能 我一直很疑惑百度.谷哥搜索框的下拉联想功能是怎么实现的?是不断地查询数据库吗?其实到现在我也不知道,他们 ...
- SupportV7包中 SwipeRefreshLayout 修改下拉控件的距离
//修改下拉距离 ViewTreeObserver vto = mCategoryResults.mSwipeRefreshLayout.getViewTreeObserver(); vto.addO ...
- ComboBox 自动调整组合框下拉部分的宽度
/// <summary> /// ComboBox 自动调整组合框下拉部分的宽度 /// </summary> void Resiz ...
- layui 根据根据后台数据动态创建下拉框并同时默认选中
第一步 form表单里写好一个下拉框 <div class="layui-form-item"> <label class="layui-for ...
- Jquery动态设置下拉框selected --(2018 08/12-08/26周总结)
1.Jquery动态根据内容设置下拉框selected 需求就是根据下拉框的值动态的设置为selected,本以为很简单,网上一大推的方法,挨着尝试了之后却发现没有一个是有用的.网上的做法如下: &l ...
- WPF-学习笔记 动态修改控件Margin的值
原文:WPF-学习笔记 动态修改控件Margin的值 举例说明:动态添加一个TextBox到Grid中,并设置它的Margin: TextBox text = new TextBox(); t_gri ...
- jquery 根据后台传过来的值动态设置下拉框、单选框选中
更多内容推荐微信公众号,欢迎关注: jquery 根据后台传过来的值动态设置下拉框.单选框选中 $(function(){ var sex=$("#sex").val(); va ...
随机推荐
- xcopy 提示文件 还是目录
xcopy /y a.jpg .\pics\b.jpg很多次,但xcopy总是问我“文件名还是目录名”gg了一下,发现答案可以这样通过管道来做echo f | xcopy /y a.jpg .\pic ...
- BZOJ2216 Poi2011 Lightning Conductor 【决策单调性优化DP】
Description 已知一个长度为n的序列a1,a2,...,an. 对于每个1<=i<=n,找到最小的非负整数p满足 对于任意的j, aj < = ai + p - sqrt( ...
- jQuery 异步和同步请求
在jQuery Ajax里面有一个async 参数 , 默认值 为true , 请求为异步请求 , false 为同步请求 .. 使用ajax加载数据返回页面并赋值,然后前端取出该值 这其中涉及到代码 ...
- linux 系统下配置java环境变量
liunx桌面版本系统下载地址:http://www.ubuntukylin.com/downloads/ 1.源码包准备: 首先到官网下载jdk,http://www.oracle.com/tech ...
- worldpress自定义页面
一:wordpress制作自定义页面的方法 有时候我们需要制作一些个性化的页面,而不是直接用wordpress的page页面模板.这时候我们就需要自已写一个页面出来.下面介绍一下制作流程: 第一步:制 ...
- 聊聊Oracle 11g的Snapshot Standby Database(下)
3.Snapshot Standby行为研究 下面我们分析一下Snapshot Standby的工作性质和行为性质.我们在主库方向研究当前状态. --主库日志情况 SQL> select gro ...
- spss v21.0 使用笔记
spss v21.0 使用笔记 有问题,戳官方帮助文档 神经网络 分析-神经网络-多层感知机 变量. 分析-神经网络-多层感知机-变量 预测变量可指定为因子(分类)或协变量(刻度). 在因变量框输入预 ...
- 记一笔vue中的中央事件总线的问题,以及解决方案
代码结构:首先HeaderNav组件是被单独拎出来的,router-view中就对应了内容组件,由于有时候i有的界面的header内容是不一样的,因此要用到兄弟组件的相互通信,这个时候我首先选择了bu ...
- javascript系列学习----对象相关概念理解
1.构造函数(相对于面向对象编程语言里面的类) 2.对象实例(它是由构造函数构造出来的对象,使用到关键字 new) 3.this关键字(往往是指我们的对象本身) 下面我们来看一个实例: var Per ...
- sed命令n,N,d,D,p,P,h,H,g,G,x解析
1.sed执行模板=sed '模式{命令1;命令2}'即逐行读入模式空间,执行命令,最后输出打印出来2.为方便下面,先说下p和P,p打印当前模式空间内容,追加到默认输出之后,P打印当前模式空间开端至\ ...