jQuery MiniUI

标题: 关于表格动态设置列的问题,求指导。 [打印本页]

作者: wj597362899    时间: 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();方法也是可以设置列的唯独直接给列赋值是不可以的。

这样写是不可以的列名不会显示。求解答。
作者: felt    时间: 2017-8-9 08:58:27

columns必须是一个数组,你加了引号就不对了。




欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2