easyui框架中 在datagrid中添加行和行编辑 组合combobox时遇到的问题 框架datagridComboBoxeasyui 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function Loading() { var editRow = undefined;//保存行的索引 var query= $("#myform").serializeObject(); $("#tabTopicList").datagrid({ url: 'Tools/GetTopicList.ashx', queryParams:query, pagination: true, width: 800, height:350, pageSize: 10, pageList: [10, 50], fit: true, fitColumns: true, nowarp: false, idField: 'top_id', sortName: 'top_createtime', sortOrder: 'desc', columns: [[ { field: 'cbx', checkbox: true }, { title: '类别', field: 'cat_title', width:80, editor: { type: 'combobox', options: { required: true, missingMessage: '请选择类别', url: 'Tools/GetTopicCategory.ashx', valueField: 'Cat_Id', textField: 'Cat_Title', onSelect: function (record) { //重点在此处 //先获取到当前选中行 //根据当前行获取,当前行的下标 //在根据下标和要获取列的filed获取对应filed的Editor对象 //然后在根据对应的Editor操作 var row = $("#tabTopicList").datagrid('getSelected'); var rindex = $("#tabTopicList").datagrid('getRowIndex', row); console.log(rindex); var ed = $("#tabTopicList").datagrid('getEditor', { index: rindex, field: 'cat_title' }); console.log($(ed.target).combobox('getText')); var msg = $(ed.target).combobox('getText'); if (msg == '单选题') { console.log(1); var rows = getEditRow(rindex, 'top_answer'); //这里能对答案的combobox赋值为2 //$(rows.target).combobox('setValues','2'); //这里我以为能这样操作, //既然可以操作方法, 为什么就不能重新定义data数据呢 //$(rows.target).combobox({ // data:[{ // label: 'A', // value:'A' // }, { // label: 'B', // value: 'B' // },{ // label: 'C', // value: 'C' // }, { // label: 'D', // value: 'D' // }] //}); } else if (msg == '多选题') { console.log(2); var rows = getEditRow(rindex, 'top_answer'); $(rows.target).combobox('setValues', '1'); } }, } } }, { title: '题目', field: 'top_description', width: 80, editor: { type: 'validatebox', options: { required: true, missingMessage: '请输入题目' } } }, { title: '选项A', field: 'top_answera', width: 80, editor: { type: 'validatebox', options: { required: true, missingMessage:'请输入选项A' } } }, { title: '选项B', field: 'top_answerb', width: 80, editor: { type: 'validatebox', options: { required: true, missingMessage: '请输入选项B' } } }, { title: '选项C', field: 'top_answerc', width: 80, editor: { type: 'validatebox', options: { required: true, missingMessage: '请输入选项C' } } }, { title: '选项D', field: 'top_answerd', width: 80, editor: { type: 'validatebox', options: { required: true, missingMessage: '请输入选项D' } } }, { title: '答案', field: 'top_answer', width: 80, editor: { type: 'combobox', options: { required: true, missingMessage: '请选择答案', multiple: true, editable: false, valueField: 'label', textField: 'value', formatter:function (row) { //console.log(row); return "<input type=\"checkbox\" name=\"" + row.label + "\" id=\"" + row.value + "\"/>" + row.value; }, onSelect:function (rec) { //console.log(rec.value); $("#" + rec.value).attr("checked", "checked"); }, onUnselect: function (rec) { $("#" + rec.value).removeAttr("checked"); }, } } }, { title: '类型', field: 'top_name', width: 80, editor: { type: 'combobox', options: { required: true, missingMessage: '请选择类型', multiple: true, editable: false, valueField: 'Top_Id', textField: 'Top_Name', url: 'Tools/getTopicTypeList.ashx', formatter: function (row) { //console.log(row); return "<input type=\"checkbox\" name=\"" + row.Top_Id + "\" id=\"" + row.Top_Id + "\"/>" + row.Top_Name; }, } } }, { title: '创建人', field: 'sta_username', width: 80 }, { title: '创建时间', field: 'top_createtime', width: 80 } ]] }); } toolbar:[{ text: '添加', iconCls: 'icon-add', handler: function () { if (editRow != undefined) { $("#tabTopicList").datagrid('endEdit', editRow); } if (editRow == undefined) { $("#tabTopicList").datagrid('insertRow', { index: 0, // index start with 0 row: { } }); $("#tabTopicList").datagrid('beginEdit', 0); editRow = 0; } } },'-', { text: '修改', iconCls: 'icon-edit', handler:function () { var rows = $("#tabTopicList").datagrid('getSelections'); if(rows.length==1) { if (editRow != undefined) { $("#tabTopicList").datagrid('endEdit', editRow); } if (editRow == undefined) { var index = $("#tabTopicList").datagrid('getRowIndex',rows[0]); $("#tabTopicList").datagrid('beginEdit', index); editRow = index; //$("#tabTopicList").datagrid('unselectAll'); } } } },'-', { text: '删除', iconCls: 'icon-remove', handler:function () { var rows = $("#tabTopicList").datagrid('getSelections'); if (rows.length > 0) { $.messager.confirm('请确认', '您确定要删除当前所有选择的项目吗?', function(b) { if(b) { var ids = []; for (var i = 0; i < rows.length; i++) { ids.push(rows[i].top_id); } console.log(ids.join(',')); } }); } else { $.messager.alert('提示', '请选择要删除的记录', 'error'); } } },'-', { text: '保存', iconCls: 'icon-save', handler:function () { $("#tabTopicList").datagrid('endEdit', editRow); } },'-', { text: '取消编辑', iconCls: 'icon-redo', handler:function () { editRow = undefined; $("#tabTopicList").datagrid('rejectChanges'); $("#tabTopicList").datagrid('unselectAll'); } }, '-'], onAfterEdit: function (rowIndex, rowData, changes) { console.log(rowData); //console.log(rowData.); //$.ajax({ //}); editRow = undefined; }, onDblClickRow: function (rowIndex, rowData) { if (editRow != undefined) { $("#tabTopicList").datagrid('endEdit', editRow); } if (editRow == undefined) { $("#tabTopicList").datagrid('beginEdit', rowIndex); editRow = rowIndex; } } CSDN。这边EASYUI的人很少。基本有问都没有人回答。还是自己解决吧。 用户名注册 能不能获得 li 的 id?或者用其他方法实现? Web.sitemap写法!!!在线等 求软件注册实现的思路,目前想通过rsa来生成密钥对,私钥加密,然后把密文和公钥给用户 dataset 怎么添加两行数据 后台赋值给服务器文本控件怎么赋值 在IE浏览器中如何直接显示word文档? 如何在页面中访问其所加载的控件的元素 oracle数据库连接问题 经过1-3分钟的I/O操作后,Session丢失!!何解? asp.net里,服务器控件的属性里引用变量的问题。 gridview在没有数据时添加一行,用来添加新数据
var editRow = undefined;//保存行的索引
var query= $("#myform").serializeObject();
$("#tabTopicList").datagrid({
url: 'Tools/GetTopicList.ashx',
queryParams:query,
pagination: true,
width: 800,
height:350,
pageSize: 10,
pageList: [10, 50],
fit: true,
fitColumns: true,
nowarp: false,
idField: 'top_id',
sortName: 'top_createtime',
sortOrder: 'desc',
columns: [[
{ field: 'cbx', checkbox: true },
{
title: '类别',
field: 'cat_title',
width:80,
editor: {
type: 'combobox',
options: {
required: true,
missingMessage: '请选择类别',
url: 'Tools/GetTopicCategory.ashx',
valueField: 'Cat_Id',
textField: 'Cat_Title',
onSelect: function (record) {
//重点在此处
//先获取到当前选中行
//根据当前行获取,当前行的下标
//在根据下标和要获取列的filed获取对应filed的Editor对象
//然后在根据对应的Editor操作
var row = $("#tabTopicList").datagrid('getSelected');
var rindex = $("#tabTopicList").datagrid('getRowIndex', row);
console.log(rindex);
var ed = $("#tabTopicList").datagrid('getEditor', {
index: rindex,
field: 'cat_title'
});
console.log($(ed.target).combobox('getText'));
var msg = $(ed.target).combobox('getText');
if (msg == '单选题') {
console.log(1);
var rows = getEditRow(rindex, 'top_answer');
//这里能对答案的combobox赋值为2
//$(rows.target).combobox('setValues','2');
//这里我以为能这样操作,
//既然可以操作方法, 为什么就不能重新定义data数据呢
//$(rows.target).combobox({
// data:[{
// label: 'A',
// value:'A'
// }, {
// label: 'B',
// value: 'B'
// },{
// label: 'C',
// value: 'C'
// }, {
// label: 'D',
// value: 'D'
// }]
//});
} else if (msg == '多选题') {
console.log(2);
var rows = getEditRow(rindex, 'top_answer');
$(rows.target).combobox('setValues', '1');
}
},
}
}
},
{
title: '题目',
field: 'top_description',
width: 80,
editor: {
type: 'validatebox',
options: {
required: true,
missingMessage: '请输入题目'
}
}
},
{
title: '选项A',
field: 'top_answera',
width: 80,
editor: {
type: 'validatebox',
options: {
required: true,
missingMessage:'请输入选项A'
}
}
},
{
title: '选项B',
field: 'top_answerb',
width: 80,
editor: {
type: 'validatebox',
options: {
required: true,
missingMessage: '请输入选项B'
}
}
},
{
title: '选项C',
field: 'top_answerc',
width: 80,
editor: {
type: 'validatebox',
options: {
required: true,
missingMessage: '请输入选项C'
}
}
},
{
title: '选项D',
field: 'top_answerd',
width: 80,
editor: {
type: 'validatebox',
options: {
required: true,
missingMessage: '请输入选项D'
}
}
},
{
title: '答案',
field: 'top_answer',
width: 80,
editor: {
type: 'combobox',
options: {
required: true,
missingMessage: '请选择答案',
multiple: true,
editable: false,
valueField: 'label',
textField: 'value',
formatter:function (row) {
//console.log(row);
return "<input type=\"checkbox\" name=\"" + row.label + "\" id=\"" + row.value + "\"/>" + row.value;
},
onSelect:function (rec) {
//console.log(rec.value);
$("#" + rec.value).attr("checked", "checked");
},
onUnselect: function (rec) {
$("#" + rec.value).removeAttr("checked");
},
}
}
}, {
title: '类型',
field: 'top_name',
width: 80,
editor: {
type: 'combobox',
options: {
required: true,
missingMessage: '请选择类型',
multiple: true,
editable: false,
valueField: 'Top_Id',
textField: 'Top_Name',
url: 'Tools/getTopicTypeList.ashx',
formatter: function (row) {
//console.log(row);
return "<input type=\"checkbox\" name=\"" + row.Top_Id + "\" id=\"" + row.Top_Id + "\"/>" + row.Top_Name;
},
}
}
},
{
title: '创建人',
field: 'sta_username',
width: 80
},
{
title: '创建时间',
field: 'top_createtime',
width: 80
}
]]
});
}
text: '添加',
iconCls: 'icon-add',
handler: function () {
if (editRow != undefined) {
$("#tabTopicList").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#tabTopicList").datagrid('insertRow', {
index: 0, // index start with 0
row: {
}
});
$("#tabTopicList").datagrid('beginEdit', 0);
editRow = 0;
}
}
},'-', {
text: '修改',
iconCls: 'icon-edit',
handler:function () {
var rows = $("#tabTopicList").datagrid('getSelections');
if(rows.length==1) {
if (editRow != undefined) {
$("#tabTopicList").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
var index = $("#tabTopicList").datagrid('getRowIndex',rows[0]);
$("#tabTopicList").datagrid('beginEdit', index);
editRow = index;
//$("#tabTopicList").datagrid('unselectAll');
}
}
}
},'-', {
text: '删除',
iconCls: 'icon-remove',
handler:function () {
var rows = $("#tabTopicList").datagrid('getSelections');
if (rows.length > 0) {
$.messager.confirm('请确认', '您确定要删除当前所有选择的项目吗?', function(b) {
if(b) {
var ids = [];
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].top_id);
}
console.log(ids.join(','));
}
});
} else {
$.messager.alert('提示', '请选择要删除的记录', 'error');
}
}
},'-', {
text: '保存',
iconCls: 'icon-save',
handler:function () {
$("#tabTopicList").datagrid('endEdit', editRow);
}
},'-', {
text: '取消编辑',
iconCls: 'icon-redo',
handler:function () {
editRow = undefined;
$("#tabTopicList").datagrid('rejectChanges');
$("#tabTopicList").datagrid('unselectAll');
}
}, '-'],
onAfterEdit: function (rowIndex, rowData, changes) {
console.log(rowData);
//console.log(rowData.);
//$.ajax({
//});
editRow = undefined;
},
onDblClickRow: function (rowIndex, rowData) {
if (editRow != undefined) {
$("#tabTopicList").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#tabTopicList").datagrid('beginEdit', rowIndex);
editRow = rowIndex;
}
}
基本有问都没有人回答。还是自己解决吧。