1
角度コントローラからのJqueryデータテーブルのデータ初期化の問題に直面しています。以下のアプローチを見つけてください。 私がように、1つの角度のコントローラをしました:角度jsコントローラからデータテーブルのデータを初期化する
app.controller('CompanyController', ['$scope', 'CompanyService',function($scope, companyService) {
var self = this;
self.companies=[];
self.fetchAllCompanies = function() {
companyService.fetchAllCompanies().then(function(d) {
self.companies = d;
},
function(errResponse) {
console.error('Error while fetching Compnies');
});
};
//self.fetchAllCompanies();
$scope.dataTableOpt = {
"aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
"searching": true
};
}]);
HTMLコードがある :
<div class="row" ng-controller="CompanyController as ctrl">
<table id="company-details" class="table table-bordered table-striped" ui-jq="dataTable" ui-options="dataTableOpt">
<thead>
<tr>
<th>Company Name</th>
<th class="text-center">Created Date</th>
<th class="text-center">Modified Date</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="company in ctrl.companies">
<td>{{company.companyName}}</td>
<td class="text-center">{{company.createdDate | date:'MMM dd, yyyy'}}</td>
<td class="text-center">{{company.modifiedDate | date:'MMM dd, yyyy'}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Company Name</th>
<th class="text-center">Created Date</th>
<th class="text-center">Modified Date</th>
</tr>
</tfoot>
</table></div>
私は角データテーブルを使用していますし、これは期待通りに働いているが、1つの問題がある:私は、行のコメントを外した場合 は//self.fetchAllCompanies();
私のコントローラからデータテーブルのデータが読み込まれますが、ソートデータの検索は行われていません。
しかし、私のコントローラでself.companies=[];
にハードコードされたjsonを割り当てた場合、データテーブルはすべて問題なく処理されますが、今度は問題self.fetchAllCompanies()
を呼び出してデータを初期化していますが、
助けてください。 ありがとう Jitender
こんにちは、実際に私はjquiの部分に問題はないと思うのですが、それはdatatableに機能を追加することで、期待どおりに動作しています。私の主な関心事は、私は関数の外で行うことはできませんサービスメソッドからコントローラself.companies = angular.toJson(companyService.fetchAllCompanies());私はこれを達成すれば、それは動作するでしょう、サービスメソッドfetchAllComapniesは、コントローラのこの時点で実際の応答を返していません。 – Jitender