- 注册时间
- 2017-5-24
- 最后登录
- 1970-1-1
- 阅读权限
- 10
- 积分
- 256
- 精华
- 0
- 帖子
- 58
|
本帖最后由 wj597362899 于 2017-8-8 22:18 编辑
下面是源码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script src="../../scripts/boot.js" type="text/javascript"></script>
</head>
<body>
<input type="button" onclick="createGrid()" value="动态设置列"/>
<div id="datagrid1" class="mini-datagrid" style="width:700px;height:280px;"
allowCellEdit="true"allowCellSelect="true"
>
</div>
</body>
</html>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
function createGrid() {
grid.set({
columns:
[
{"allowSort":false,"editor":{"type":"textbox"},"field":"name","header":"姓名","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"type":"textbox"},"field":"gender","header":"性别","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"allowInput":false,"onbuttonclick":"selectPerson(this,{\"filter\":\"\",\"groupBy\":3,\"singleMode\":true,\"syncMode\":false})","showClose":true,"type":"buttonedit"},"field":"person","header":"人员","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"data":[{"id":"1","text":"aaa"},{"id":"2","text":"bbb"},{"id":"3","text":"ccc"},{"id":"4","text":"ddd"}],"multiSelect":"true","type":"combobox"},"field":"combox","header":"下拉框","headerAlign":"center","type":"comboboxcolumn","width":120},
{"allowSort":false,"editor":{"data":[{"id":"1","text":"同意"},{"id":"2","text":"不同意"}],"type":"combobox"},"field":"danxuan","header":"单选","headerAlign":"center","type":"comboboxcolumn","width":120}
]
});
grid.load();
}
</script>
当点击动态设置列是OK的,列也能正常赋值。
但是当我将这个array写到 columns属性中就不行,比如
columns="[
{"allowSort":false,"editor":{"type":"textbox"},"field":"name","header":"AAA","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"type":"textbox"},"field":"gender","header":"BBB","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"allowInput":false,"onbuttonclick":"selectPerson(this,{\"filter\":\"\",\"groupBy\":3,\"singleMode\":true,\"syncMode\":false})","showClose":true,"type":"buttonedit"},"field":"person","header":"人员","headerAlign":"center","width":120},
{"allowSort":false,"editor":{"data":[{"id":"1","text":"aaa"},{"id":"2","text":"bbb"},{"id":"3","text":"ccc"},{"id":"4","text":"ddd"}],"multiSelect":"true","type":"combobox"},"field":"combox","header":"下拉框","headerAlign":"center","type":"comboboxcolumn","width":120},
{"allowSort":false,"editor":{"data":[{"id":"1","text":"同意"},{"id":"2","text":"不同意"}],"type":"combobox"},"field":"danxuan","header":"单选","headerAlign":"center","type":"comboboxcolumn","width":120}
]"
另外我通过grid.setColumns();方法也是可以设置列的唯独直接给列赋值是不可以的。
这样写是不可以的列名不会显示。求解答。 |
|