代码之家  ›  专栏  ›  技术社区  ›  Sathish

如何在JS网格MVC中创建动态列

  •  0
  • Sathish  · 技术社区  · 6 年前

    在我的项目中,我需要基于API控制器数据创建动态列。

    我试图在字段中使用for循环,它显示错误。

    在我的代码中,我只是尝试在循环内创建列,然后我计划为每个循环传入viewbag。正确的方法?

    我的尝试:

    $("#jsGrid").jsGrid({
        height: "100%",
        width: "100%",
        filtering: true,
        editing: false,
        inserting: false,
        sorting: true,
        paging: true,
        autoload: true,
        pageSize: 15,
        pageButtonCount: 5,
        noDataContent: "No data found",
        controller: {
            loadData: function(filter) {
                return $.ajax({
                    type: "GET",
                    url: "/api/data?xWhere=" + xWhere,
                    data: filter,
                    dataType: "json"
                });
            },
        },
        fields: [
            for (i = 1; i < 2; i++) {
                {
                    name: "UserName",
                    title: "User Name",
                    type: "text",
                    width: 150
                }
            }
        ]
    });
    $("#jsGrid").jsGrid("option", "filtering", false);
    });
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   yusuf hayırsever    6 年前

    我认为,以下方法比你的方法更适用。但这是你的决定。

    参观 https://www.syncfusion.com/forums/123170/add-columns-dynamically-from-controller-or-through-script