Thuy Linh Nguyen
Thuy Linh Nguyen

Reputation: 1

dgrid/Grid setting dynamic column field

I'm new to dgrid/Grid. I have problem when set the last field to columns of Grid. My data array:

[{
    "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"
}]

I save my data array to ViewBag.Data and here is my code:

<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>

I had read https://github.com/SitePen/dgrid/blob/v0.4.3/doc/components/core-components/Grid.md but have no idea. Can any one help me?

Thanks a lot!

Upvotes: 0

Views: 294

Answers (1)

Thuy Linh Nguyen
Thuy Linh Nguyen

Reputation: 1

Finally, I solved my problem. First, get your data as a datatable, then you convert it into a json array. Second, in html you bind Json array to the Grid's store. Because the last column is dynamic, so you can get datatable column and convert to Json array to use in HTML. Hope this help someone else.

Upvotes: 0

Related Questions