为angularjs控制器

时间:2018-04-27 10:02:08

标签: javascript angularjs asp.net-mvc razor angular-datatables

我正在尝试为数据表中的页面更改编写事件处理程序。以下是现有代码..这些库包含在baselayout中,用于以下代码..

DefaultView.cshtml    

<div class="row">
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pageheading">
        <h1>
            <small>AMS Default</small>
        </h1>
    </div>
</div>
<hr />
<br />

<div class="row">
    <div class="col-lg-12">
        <table dt-options="dtOptions" datatable dt-columns="dtColumns"
               class="table table-striped table-bordered dt-responsive">
            <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
        </table>
    </div>
</div>

@section CommonScripts{
    <script src="~/Angular/Areas/Common/Controllers/DefaultController.js"></script>
    <script src="~/Angular/Areas/Common/Services/DefaultService.js"></script>
}

Defaultcontroller.js

    AMSApp.controller('DefaultController', ['$rootScope', 'DefaultService', 'DTOptionsBuilder', 'DTColumnBuilder',

        function ($rootScope, DefaultService, DTOptionsBuilder, DTColumnBuilder) {
        var self = this;

        this.Users = {};

        this.GetAllUsers = function () {
            $rootScope.CloseAlerts();

            DefaultService.GetAllUsers().success(function (result) {
                self.Users = result;
                self.loadd();
            }).catch(function (error) {
                $rootScope.ErrorMsg = "OOPS some thing went wrong. Please try again.";
            });
        }

        this.GetAllUsers();

        this.loadd = function () {
            $rootScope.dtColumns = [
                DTColumnBuilder.newColumn('DisplayName').withTitle('UserName'),
                DTColumnBuilder.newColumn('IsSNA').withTitle('IsSNA'),
                DTColumnBuilder.newColumn('IsAdmin').withTitle('IsAdmin'),
                DTColumnBuilder.newColumn('IsDownloadPermitted').withTitle('DownloadPermitted')
            ];

            $rootScope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('data', self.Users)
            .withDisplayLength(10);
        }



    }]);

    /*

    Button Click handler:

        $("#customerSearchButton").on("click", function (event) {
            $.ajax({
                url: "",
                type: "post",
                data: { searchText: searchText }
            }).done(function (result) {
                Table.clear().draw();
                Table.rows.add(result).draw();
            }).fail(function (jqXHR, textStatus, errorThrown) {
                // needs to implement if it fails
            });
        }

    */

DefaultService.js

AMSApp.service('DefaultService', function ($http) {
    this.GetAllUsers = function () {
        return $http.get('/Common/User/GetAllUsers');
    }
});

我尝试了几个版本,就像上面注释的代码一样......但是我需要在控制器中跟随以下内容。

/*need something like this*/
            DTOptionsBuilder.on('page.dt', function () {
                var info = table.page.info();
                console.log("hey i got eexecuted");
                $('#pageInfo').html('Showing page: ' + info.page + ' of ' + info.pages);
            });

首先是可能的吗? - 如果没有其他替代方案?

注意:我不想给表提供id。

0 个答案:

没有答案