jQuery MiniUI

 找回密码
 立即注册
查看: 3727|回复: 1
打印 上一主题 下一主题

关于表格动态设置列的问题,求指导。 [复制链接]

Rank: 3Rank: 3

跳转到指定楼层
楼主
发表于 2017-8-8 22:11:47 |只看该作者 |倒序浏览
本帖最后由 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();方法也是可以设置列的唯独直接给列赋值是不可以的。

这样写是不可以的列名不会显示。求解答。

Rank: 8Rank: 8

沙发
发表于 2017-8-9 08:58:27 |只看该作者
columns必须是一个数组,你加了引号就不对了。

Archiver|普加软件

GMT+8, 2024-11-19 03:42 , Processed in 1.033429 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部