jqgrid下拉框多选
时间: 2023-12-03 11:38:10 浏览: 42
jqgrid下拉框可以实现多选功能,具体实现方法如下:
1. 设置colModel中的edittype为select,同时设置editoptions中的multiple为true,例如:
```
{name:'fruit',index:'fruit', width:90, editable: true, edittype:"select", editoptions:{value:"apple:苹果;banana:香蕉;orange:橙子", multiple:true}}
```
2. 在colModel中设置formatter为select,同时设置editoptions中的multiple为true,例如:
```
{name:'fruit',index:'fruit', width:90, editable: true, formatter:'select', edittype:"select", editoptions:{value:"apple:苹果;banana:香蕉;orange:橙子", multiple:true}}
```
以上两种方法都可以实现下拉框多选功能,具体使用哪种方法取决于你的需求。
相关问题
jquery.jqGrid 下拉框
在 `jquery.jqGrid` 中,可以使用 `edittype` 属性为某一列设置编辑类型,从而实现下拉框的功能。具体实现步骤如下:
1. 定义下拉框选项
定义一个 JavaScript 对象,用于存储下拉框选项,其中键为选项的值,值为选项的文本。例如:
```javascript
var genderOptions = {
"男": "男",
"女": "女"
};
```
2. 设置列的 `edittype` 属性
在 `colModel` 中设置某一列的 `edittype` 属性为 "select",并在 `editoptions` 中设置下拉框的选项。例如:
```javascript
colModel: [
{name: "id", width: 60},
{name: "name", width: 100},
{name: "age", width: 60},
{name: "gender", width: 60, edittype: "select", editoptions: {value: genderOptions}},
],
```
其中,`edittype` 属性指定编辑类型为 "select",`editoptions` 属性用于设置下拉框的选项,其中 `value` 属性用于指定选项的值和文本。
完整代码如下:
```javascript
var genderOptions = {
"男": "男",
"女": "女"
};
$("#grid").jqGrid({
url: "data.json",
datatype: "json",
colNames: ["编号", "姓名", "年龄", "性别"],
colModel: [
{name: "id", width: 60},
{name: "name", width: 100},
{name: "age", width: 60},
{name: "gender", width: 60, edittype: "select", editoptions: {value: genderOptions}},
],
rowNum: 10,
rowList: [10, 20, 30],
pager: "#pager",
autowidth: true,
height: "auto",
});
```
这样就可以在 "性别" 列中使用下拉框了。
jqgrid下拉框怎么配置
在 jqGrid 中配置下拉框可以使用 `editoptions` 属性,该属性用于设置编辑操作的选项。具体的配置方式如下:
1. 定义下拉框数据源
```javascript
var mydata = [
{ id: "1", name: "John", city: "New York" },
{ id: "2", name: "Bob", city: "Los Angeles" },
{ id: "3", name: "Mike", city: "Chicago" },
{ id: "4", name: "Tom", city: "Houston" },
{ id: "5", name: "Jerry", city: "Miami" }
];
```
2. 配置列模型
```javascript
colModel: [
{ name: 'id', index: 'id', width: 60, editable: true },
{ name: 'name', index: 'name', width: 90, editable: true },
{ name: 'city', index: 'city', width: 100, editable: true, edittype: "select",
editoptions: { value: "New York:New York;Los Angeles:Los Angeles;Chicago:Chicago;Houston:Houston;Miami:Miami" } }
]
```
在上面的代码中,我们在第三列中配置了下拉框。`edittype` 属性设置为 `select` 表示使用下拉框进行编辑,`editoptions` 属性中的 `value` 值定义了下拉框的选项列表。
如果下拉框的选项比较多,可以将选项列表存储在一个数组中,并通过 JavaScript 动态生成选项列表。例如:
```javascript
var cities = [
{ id: "NY", name: "New York" },
{ id: "LA", name: "Los Angeles" },
{ id: "CH", name: "Chicago" },
{ id: "HO", name: "Houston" },
{ id: "MI", name: "Miami" }
];
var cityOptions = "";
for (var i = 0; i < cities.length; i++) {
cityOptions += cities[i].id + ":" + cities[i].name + ";";
}
colModel: [
{ name: 'id', index: 'id', width: 60, editable: true },
{ name: 'name', index: 'name', width: 90, editable: true },
{ name: 'city', index: 'city', width: 100, editable: true, edittype: "select",
editoptions: { value: cityOptions } }
]
```
这样就可以通过 `cities` 数组动态生成下拉框选项了。