0

我正在研究 js-grid,我正在尝试找到一种将列动态添加到网格的方法。我知道有一种添加行的方法,但我想看看网格是否具有使用按钮添加列的功能。我一直在阅读文档,不确定这是否可能。我的代码如下所示。任何帮助示例或资源将不胜感激。

`var data = [ { "Name": "Christopher", "Married": false, "Testing": "Here", "Col": "new" }, { "Name": "David", "Married":假,“Testing”:“Here”,“Col”:“new”},{“Name”:“Sal”,“Married”:true,“Testing”:“Here”,“Col”:“new”} , { "Name": "Mike", "Married": false, "Testing": "Here", "Col": "new" } ];

$j("#jsGrid").jsGrid({
        height: 300,
        width: "100%",

        paging: true,
        autoload: true,
        inserting: true,
        editButton: true,
        editing: true,


        pageSize: 6,

        controller: {
            loadData: function() {
            return data;
        }
    },


    onRefreshed: function(args) {
            var items = args.grid.option("data");
            console.log( items, 'lets get dangerous')
         },

    fields: [

        { name: "Name", itemTemplate:function(value, item){
            if(!value){
                value = 'new';
                return item.Name = value;
            }else{
                return item.Name = value;
            }
        }, type: "textarea", width: 50 },




        { name: "Testing", itemTemplate:function(value, item){
            if(!value){
                value = 'new';
                return item.Testing = value;
            }else{
                return item.Testing = value;
            }
        }, type: "textarea",width: 50, height: 50},


        { name: "Col", itemTemplate:function(value, item){
            if(!value){
                value = 'new';
                return item.Col = value;
            }else{
                return item.Col = value;
            }
        }, type: "textarea",width: 50, height: 50},
        { type: "control" },

    ]

});`
4

1 回答 1

1

您可以将网格的新列设置fields选项添加到新的列(字段)数组中:

$("#grid").jsGrid("option", "fields", newFieldsArray);

拥有初始字段集,将新列推送到它并设置fields网格选项。

于 2017-07-29T20:33:52.760 回答