如何将List <string []>绑定到Telerik Asp.net Grid?

时间:2018-04-29 08:39:31

标签: c# asp.net telerik

我有一个具有此架构的类,我想在Telerik asp.net mvc网格上显示它。

public interface IOutPutReport
{
    string S_ReportName { get; }
    string[] LiHeader { get; }
    List<string[]> LiData { get; }
    int I_Count { get; }
}

我的数据格式很灵活:DataRows在LiData中,列名存储在LiHeader中! 我使用这个jQuery方法找到了它的解决方案:

$("#myDiv").remove();
            $.ajax({
                type: "POST",
                url: '@Url.Action("ShowReport", "Report")',
                traditional: true,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    //alert(response.LiHeader);
                    //alert(response.LiData);

                    var rows = [];
                    for (var i = 0; i < response.LiData.length; i++) {
                        var entryArray = [];
                        for (var j = 0; j < response.LiData[i].length; j++) {
                            entryArray.push(response.LiData[i][response.LiData[i].length - 1 - j]);
                        }
                        rows.push(kendo.observable({
                            entries: entryArray
                        }));
                    }

                    var viewModel = kendo.observable({
                        gridRows: rows
                    });

                    var columns = [];

                    for (var i = 0; i < response.LiHeader.length; i++) {
                        var entryIndex = "entries[" + i + "]";
                        columns.push({
                            field: entryIndex,
                            title: response.LiHeader[response.LiHeader.length - 1 - i],
                            filterable: true
                        });
                    }

                    var configuration = {
                        editable: false,
                        sortable: true,
                        filterable: true,
                        scrollable: false,
                        pageable:
                        {
                            pageSize: 25
                        },
                        columns: columns
                    };

                    var timeEditGrid = $("#grid").kendoGrid(configuration).data("kendoGrid");


                    kendo.bind($('#example'), viewModel);


                },
                failure: function (response) {
                    alert(response.responseText);
                },
                error: function (response) {
                    alert(response.responseText);
                }
            });
            return false;
        });
    });

有没有办法将LiData显示为数据行,而LiHeader是Telerik asp.net网格上的列显示名称,使用Asp.net razor方法提供jQuery?

更新1:我期望的东西就像这段代码:

@(Html.Kendo().Grid(Model)
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(c => c.LiData[0]);
                columns.Bound(c => c.LiData[1]);
                columns.Bound(c => c.LiData[2]).Width(150);
            })
            .HtmlAttributes(new { style = "height: 550px;" })
            .Scrollable()
            .Groupable()
            .Sortable()
            .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(5))
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("Customers_Read", "Grid"))
                .PageSize(20)
            )
)

0 个答案:

没有答案