dgrid / Grid设置动态列字段

时间:2017-06-14 10:12:32

标签: dgrid

我是dgrid / Grid的新手。将最后一个字段设置为Grid列时出现问题。我的数据数组:

[{
    "StatisticType": "Năng suất lập trình",
    "Language": "PHP",
    "Phase": "Code - Review Code",
    "ProjectType": "Customize/Full",
    "Donvi": "KLOC/ManMonth",
    "**HSL**": "2.2"
}, {
    "StatisticType": "Năng suất lập trình",
    "Language": "PHP",
    "Phase": "Code - Review Code - UT",
    "ProjectType": "Customize/Full",
    "Donvi": "KLOC/ManMonth",
    "**TTP**": "1.21"
}, {
    "StatisticType": "Tỷ lệ bug phát hiện khi review source code",
    "Language": "Tính chung các ngôn ngữ",
    "Phase": "",
    "ProjectType": "Customize/Full",
    "Donvi": "bug/KLOC",
    "**CCC**": "0"
}]

我将数据数组保存到ViewBag.Data,这是我的代码:

<script>
                var report = @Html.Raw(ViewBag.Data);

                require([
                'dojo/_base/declare',
                'dstore/Memory',
                'dgrid/OnDemandGrid'
                ], function (declare, Memory, OnDemandGrid) {
                    var store = new (declare([Memory]))({
                        data: report_@(i)
                    });

                    // Instantiate grid
                    var grid = new (declare([OnDemandGrid]))({
                        collection: store,
                        columns: {
                                StatisticType: 'Số liệu thống kê',
                                Language: 'Ngôn ngữ LT',
                                Phase: 'Công đoạn',
                                ProjectType: 'Loại Project',
                                Donvi: 'Đơn vị tính',
                                "The last field of column"
                                (if I set HSL: 'HSL' it's okay but the other fields??)
                            }
                        }, 'grid');

                        grid.startup();

                    });
                </script>

我读过https://github.com/SitePen/dgrid/blob/v0.4.3/doc/components/core-components/Grid.md但不知道。谁能帮我?

非常感谢!

1 个答案:

答案 0 :(得分:0)

最后,我解决了我的问题。 首先,将您的数据作为数据表,然后转换为Json数组 其次,在html中将Json数组绑定到Grid的商店。 因为最后一列是动态的,所以你可以获取数据表列并转换为Json数组以在htnl中使用。 希望这有助于其他人。