可以将单元格编辑为下拉列表并使用 JQGard 进行多选
can make celledit to dropdown and multiselect with jqgrid?
$.(document).ready(function() {
$.ajax({
url: 'xx_op.php',
...success: function(result) {
result = JSON.parse(result);
var colNames = result.columnNames;
var colModel = result.colModel;
$.("list").jqGrid({
colNames: colNames,
colModel: colModel,
cellEdit: true,
cellsubmit: 'clientArray',
afterSaveCell: function(rowid, cellname, value, iRow, iCol) {
var y = $("group_list").getChangedCells('dirty');
var t = JSON.stringify(y);
$.ajax({
....
});
}
});
}
});
});
你能理解我的意思吗?我想将单元格编辑设置为下拉列表和多选,那么如何编写代码?这是我最终想要实现的效果图。 并且每个同名都像图片,值因同名而异
在此处输入图像描述
您需要
为要成为多选选项的列定义编辑类型和编辑选项。
这里也是关于多选的有用链接
这是我在jsfiddle中为您创建的解决方案
var mydata = [
{id: "10", Name: "dog", Singleselect: "1", Multiselect: [1]},
{id: "20", Name: "cat", Singleselect: "1", Multiselect: [2]},
{id: "30", Name: "fish", Singleselect: "2", Multiselect: [3, 4]},
{id: "40", Name: "elephant", Singleselect: "2", Multiselect: [4]}
],
lastSel;
$("#list").jqGrid({
data: mydata,
cellEdit:true,
datatype: "local",
cellsubmit: 'clientArray',
colModel: [
{ name: "Name", width: 130 },
{ name: "Singleselect", width: 100, formatter: "select", edittype: "select",
editoptions: {
value: {"1": "sport", "2": "science"},
size: 2
}
},
{ name: "Multiselect", width: 250,
formatter: "select",
edittype: "custom",
editoptions: {
value: {"1": "Swim", "2": "Eat 1", "3": "drink", "4": "bark"},
custom_element: function (value, options) {
return $.jgrid.createEl.call(this, "select",
$.extend(true, {}, options, {custom_element: null, custom_value: null}),
value);
},
custom_value: function ($elem, operation, value) {
if (operation === "get") {
return $elem.val();
}
},
multiple: true
}
}
],
cmTemplate: { editable: true },
gridview: true,
sortname: "Name",
sortorder: "desc",
viewrecords: true,
rownumbers: true,
pager: "#pager",
height: "100%",
editurl: "clientArray",
caption: "Multi select options"
});
在你的PHP中添加它,无论你在哪里创建列模型SEe 也是解决方案在这里,奥列格创造了与您的相似的
内容 editoptions:
{
'custom_element': multiselectcallback,
'custom_value': multiselectvalue,
multiple: true
}
然后把它们放到javascript中
function multiselectcallback(value, options) {
//get dropdown values using ajax and load them on success
$.get( "xx_op.php/getdropdownlistdata", function(result) {
return $.jgrid.createEl.call(this, "select", $.extend(true, {}, options, {custom_element: null, custom_value: null}), result);
}
函数多选值(elem, op, v( {
if (operation === "get")
{
return $elem.val();
}
相关文章:
- 使用jquery在单击时在单元格中输入值
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- 可以'我不明白为什么;t将行和单元格添加到表中
- 如何在Angular中的表的所有单元格中添加链接
- 表中单元格的总和
- ExtJS网格单元格编辑器,防止焦点松动问题
- 有没有一种方法可以仅使用HTML/CSS来隐藏基于特定值的数据单元格
- 区分电子表格中的空单元格和0值
- ui网格将单元格显示为选择标记
- 单元格的工具提示或标题不显示超过2000个字符
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- 允许表单元格内容水平展开
- 如何将jQuery/AAJAX结果放入表格单元格
- 使用jQuery只返回选中复选框后的第一个表单元格值
- jQuery-通过AJAX调用动态添加具有值的表单元格
- 需要将单元格值复制到html表中的其他单元格中
- 从Javascript中选定的行中获取特定单元格的值
- 使用JavaScript获取Gridview单元格值
- jQuery如何获取td单元格值
- 可以将单元格编辑为下拉列表并使用 JQGard 进行多选