人口问题json数据到剑道网格视图

时间:2019-05-07 08:22:40

标签: c# json angularjs model-view-controller kendo-grid

我是Kendo ui的新开发人员。我只是将Angularjs与Kendo网格一起应用。我想要json中的数据类型。我可以检索json数据,但不能在kendo网格中显示。请帮助

HTML:

<kendo-grid id="OpExBData" options="mainGridOptions" k-rebind="mainGridOptions"></kendo-grid>

C#代码:

public JsonResult GetData()
    {
        var sqlList = new List<SqlQuery>();

        sqlList.Add(new SqlQuery { Query = "select * from table1" });

        var dataList = idb.GetDataSet(sqlList);

        var FirstList = dataList.Tables[0].AsEnumerable()
                        .Select(row => new
                        {
        dept_code = row.Field<string>("dept_code"),
        dept_name = row.Field<string>("dept_name"),
        ca_account_no = row.Field<string>("ca_account_no"),
        account_desc = row.Field<string>("account_desc"),
        total_pre_year = row.Field<decimal>("total_pre_year")
        }).ToList();
        return Json(FirstList, JsonRequestBehavior.AllowGet);
    }

angularjs:

angular.module('myApp').controller('MyController', function ($scope, dialogService, MyService) {


    MyService.GetData().then(function (data) {
        $scope.BudgetData = data;            
        $('#OpExBData').data('kendoGrid').dataSource.transport.read();
    }, function (error) {
        dialogService.showDialogError(error);
    });


$scope.mainGridOptions = {
    dataSource: new kendo.data.DataSource({
        type: "json",
        transport: {
            read: $scope.BudgetData,
            dataType: "json"
        },            
        pageSize: 10,
        serverPaging: true,
        serverSorting: true
    }),
    sortable: true,
    pageable: true,
    dataBound: function () {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    },
    columns: [
    { field: "dept_code", title: "Dept Code" },
    { field: "dept_name", title: "Dept Name" },
    { field: "ca_account_no",title:"Acc Head No" },
    { field: "account_desc", title: "Acc Head" },
    { field: "total_pre_year", title:"Total Pre Year" }
    ]
};

});

myApp.factory('OpExBudgetEntryService',['$ http',函数($ http){     var fac = {};

fac.GetData= function () {
    return $http.get('api/GetData').then(function (response) {
        return response.data;
    });
}

return fac;

}]);

如何将json数据从数据库显示到kendo网格中,请帮忙

0 个答案:

没有答案