Datatables show no data available in the table - angularjs

Can someone help me on this matter? Here are my codes:
<div class="modal-body no-padding" style="overflow-y: scroll; max-height: 500px;">
<table width="auto" class="table report-table table-star" id="example">
<thead>
<tr>
<td class="center">#</td>
<th>Name</th>
<th>Email / Mobile</th>
<th>Date / Time</th>
<th>Excellent</th>
<th>Good</th>
<th>Average</th>
<th>Bad</th>
<th>Worse</th>
</tr>
</thead>
<tr ng-repeat="u in user_report">
<td class="center">{{$index+1}}</td>
<td>{{u.name}}</td>
<td>{{u.email}} / {{u.mobile}}</td>
<td>{{u.timestamp}}</td>
<td class="center">
<span ng-if="u.choice == 1"><i class="fas fa-check"></i></span>
<span ng-if="u.choice != 1"><i class="fas fa-times"></i></span>
</td>
<td class="center">
<span ng-if="u.choice == 2"><i class="fas fa-check"></i></span>
<span ng-if="u.choice != 2"><i class="fas fa-times"></i></span>
</td>
<td class="center">
<span ng-if="u.choice == 3"><i class="fas fa-check"></i></span>
<span ng-if="u.choice != 3"><i class="fas fa-times"></i></span>
</td>
<td class="center">
<span ng-if="u.choice == 4"><i class="fas fa-check"></i></span>
<span ng-if="u.choice != 4"><i class="fas fa-times"></i></span>
</td>
<td class="center">
<span ng-if="u.choice == 5"><i class="fas fa-check"></i></span>
<span ng-if="u.choice != 5"><i class="fas fa-times"></i></span>
</td>
</tr>
</table>
</div>
And the script below the html to call the datatable:
<script>$(document).ready(function() {$('#example').DataTable();} );</script>
By the way, it show the data but there is "No data available in the table" message on the last row. Once I click on the sorting / pagination, the data gone out from the table.

Related

Ng-show not showing product's detail

I'm making an exercise about the AngularJS, and i created a table that will load the data from database, i have a "Detail" button, when i click on that button, it will assign a new row below the row which contain a button i clicked. It's work fine but the problem is when i click the "Detail" button, it the detail of all, i just want it to show the detail of which product i clicked.
Here is my HTML code:
var app = angular.module("dataApp", []);
app.controller("dataExcuteController", function ($scope, $window,$http) {
$http.get('http://localhost:8080/sachonline/public/administrator/theloai/dstheloai').then(function (response) {
$scope.theloai = response.data.message.ds_theloai;
$scope.isLoading = false;
});
$scope.detailtheloai = function (item) {
$scope.showdetail = true;
};
});
<body ng-app="dataApp" ng-controller="dataExcuteController">
<div class="container">
<table class="table table-bordered">
<thead class="text-center">
<th>STT</th>
<th>Tên thể loại</th>
<th>Trạng thái</th>
<th>
<span><i class="fa fa-cog text-muted"></i></span>
</th>
</thead>
<tbody ng-repeat="item in theloai">
<tr>
<td class="text-center">#{{ item.tl_ma }}</td>
<td>#{{ item.tl_ten }}</td>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-warning text-white mr-3 pt-0 pl-2 pr-2" ng-click="detailtheloai(item)"><i class="fa fa-info-circle"></i></button>
<button type="button" class="btn btn-sm btn-success text-white mr-3 pt-0 pl-2 pr-2" data-toggle="modal" data-target="#editForm" ng-click="edittheloai($index)"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-sm btn-danger text-white pt-0 pl-2 pr-2" ng-click="removetheloai($index)"><i class="fa fa-trash"></i></button>
</td>
</tr>
<tr ng-show="showdetail">
<td colspan="4">
<table class="table table-info table-bordered">
<tbody>
<tr>
<th class="text-right">Mã thể loại:</th>
<td>#{{ item.tl_ma }}</td>
</tr>
<tr>
<th class="text-right">Tên thể loại:</th>
<td>#{{ item.tl_ten }}</td>
</tr>
<tr>
<th class="text-right">Trạng thái:</th>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<script src="{!!asset('js/showlist.js')!!}"></script>
</body>
You need to store the show value for every item, therefore I propose you this changes:
js:
$scope.detailtheloai = function (item) {
item.showdetail = true;
};
html:
<tr ng-show="item.showdetail">

angular js server side pagination with search without using pagination

My Get search Api looks like
"http://localhost:3000/api/driver/search/" + searchText + "/" + pagesize + "/" + page;
Functionality is like if i search using a string, it should result table with prev and next button.
For search, I need to pass page size and page number to search method.
Below is y Html looks like
<div class="input-group col-md-4 col-md-offset-8" align="center">
<input class="form-control" type="search" ng-model="searchText" placeholder="Search" />
<button class="input-group-addon" ng-click="search(searchText)">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
<br /><br />
<table class="table table-condensed table-hover table-striped table-bordered" ng-show="showtable">
<thead>
<tr>
<th class="label label-info visible-lg"><h5 class="text-capitalize">Driver ID</h5></th>
<th class="label label-info visible-lg"><h5 class="text-capitalize">Driver Name</h5></th>
<th class="label label-info visible-lg"><h5 class="text-capitalize">Contact Number</h5></th>
<th class="label label-info visible-lg"><h5 class="text-capitalize">Driver Email</h5></th>
<th class="label label-info visible-lg"><h5 class="text-capitalize">ShiftType</h5></th>
<th class="label label-info visible-lg"><h5 class="text-capitalize">Action</h5></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="driver in drivers">
<td>
<div ng-if="driver.editing"> <div ng-class="name" align="center"> {{driver.driverId}}</div> </div>
<div ng-if="driver.saving">
<div align="center">
{{driver.driverId}} </div>
</div>
</td>
<td>
<div ng-if="driver.editing"> <div ng-class="name" align="center"> {{driver.driverName}}</div> </div>
<div ng-if="driver.saving">
<div align="center"><input type="text" ng-model="driver.driverName" required /></div>
</div>
</td>
<td>
<div ng-if="driver.editing"><div align="center"> {{driver.contactNumber}}</div></div>
<div ng-if="driver.saving">
<div align="center"><input type="text" ng-model="driver.contactNumber" required /></div>
</div>
</td>
<td>
<div ng-if="driver.editing"><div align="center"> {{driver.email}}</div></div>
<div ng-if="driver.saving">
<div align="center"><input type="text" ng-model="driver.email" required /></div>
</div>
</td>
<td>
<div ng-if="driver.editing"><div align="center"> {{driver.shiftType}}</div></div>
<div ng-if="driver.saving">
<div align="center"><input type="text" ng-model="driver.shiftType" required /></div>
</div>
</td>
<td align="center">
<div ng-if="driver.editing">
<button ng-click="edit(driver, driver.driverId)" class="edit btn-info">
<i align="center" class="glyphicon glyphicon-edit"></i>
</button>
</div>
<div ng-if="driver.saving" class="btn-group">
<button align="center" ng-click="save(driver,driver.driverId)" class="glyphicon-save btn-group-sm btn-success">
<i class="glyphicon glyphicon-floppy-save"></i>
</button>
<button align="center" ng-click="cancel(driver,driver.driverId)" class="glyphicon-remove btn-group-sm btn-warning">
<i class="glyphicon glyphicon-remove"></i>
</button>
</div>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="9">
<div align="right">
<ul class="pagination">
<li ng-class="{disabled: currentPage == 0}">
<< prev
</li>
<li ng-repeat="n in range(drivers.length)" ng-class="{active: n == currentPage}" ng-click="setPage()">
1
</li>
<li ng-class="{disabled: currentPage == drivers.length - 1}">
Next »
</li>
</ul>
</div>
</td>
</tr>
</tfoot>
I am not sure how to proceed. How to input these values. Any suggestions greatly helpful.

Change collapse data-target and id automatically

Inside an ng-repeat I have a table in which I display information using Bootstap collapse, however I need the id to be changed with the loop in order for the data to be displayed in the right place, with my current code it keeps displaying in the same row with each click, here is my code :
<tr ng-repeat=" p in projetsListe ">
<td>{{p.NomProjet}}</td>
<td>{{calcul(p.IdProjet)}}</td>
<td>{{calculTotal(p.IdProjet)}}</td>
<td>{{calcul(p.IdProjet)-calculTotal(p.IdProjet)}}</td>
<td>
<a href="#" ng-click="myFunction(p.IdProjet)" data-toggle="collapse" data-target="#d">
<i class="fa fa-eye"></i>
<span>Voir les détails</span> <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="d" class="collapse">
<table id= "mytable" class="table table-hover" style="display : none;">
<thead>
<tr>
<th>Tache</th>
<th><center>Charge estimée</center></th>
<tr ng-repeat="t in tempnorep">
<td>{{t.NomTache}}</td>
<td><center>{{t.TempsPrevu}} jours<center></td>
</tr>
</table>
</ul>
</td>
</tr>
I believe you wanted to do something like:
<tr ng-repeat=" p in projetsListe ">
<td>{{p.NomProjet}}</td>
<td>{{calcul(p.IdProjet)}}</td>
<td>{{calculTotal(p.IdProjet)}}</td>
<td>{{calcul(p.IdProjet)-calculTotal(p.IdProjet)}}</td>
<td>
<a href="#" ng-click="myFunction(p.IdProjet)" data-toggle="collapse" ng-attr-data-target="#{{p.IdProjet}}">
<i class="fa fa-eye"></i>
<span>Voir les détails</span> <i class="fa fa-fw fa-caret-down"></i></a>
<ul ng-attr-id="{{p.IdProjet}}" class="collapse">
<table id= "mytable" class="table table-hover" style="display : none;">
<thead>
<tr>
<th>Tache</th>
<th><center>Charge estimée</center></th>
<tr ng-repeat="t in tempnorep">
<td>{{t.NomTache}}</td>
<td><center>{{t.TempsPrevu}} jours<center></td>
</tr>
</table>
</ul>
</td>
</tr>

angular-bootstrap 2 paginations, issue in second pagination

image showing paginations
I have item list with many tables in which initaily i show headers by loop each table header works as accordion and on click any table header one request send to get data for that header and tbody populate accordingly.
I have applied pagination on headers and its working fine but pagination on any tbody not working.
Below I have mentioned HTML code.
<div class="col-md-12">
<!-- start table one -->
<div class="table table-responsive series-tbl series-tbl-m">
<table data-ng-repeat="series in serieses track by series._id" class="table table-striped" id="headingOne">
<thead class="table-blue">
<tr >
<th width="5%"><input ng-click="checkAllTalks(series._id,series.Selected)" ng-model="series.Selected" selected="{{series.Selected}}" type="checkbox"></th>
<th width="28%">{{series.title}}</th>
<th width="22%">{{series.totalCount || 0}} talks</th>
<th width="15%">{{ series.totalDuration || 0 | timestring }}</th>
<th width="15%">${{series.totalPrice || 0}}</th>
<th width="18%" class="th-action-icon">
<!-- <i class="fa fa-plus"></i> -->
<a ng-click="openUpdateSeriesModal('md',series._id)" href="#"><i class="fa fa-pencil"></i></a>
<i class="fa fa-trash"></i>
<a role="button" ng-click="showTalks(series._id)" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"><i class="fa fa-caret-down"></i></a>
</th>
</tr>
</thead>
<tbody id="series-{{series._id}}" class="panel-collapse collapse in dn allSeriesTalks" role="tabpanel" aria-labelledby="headingOne">
<tr ng-repeat='talk in seriesTalks track by talk._id'>
<td><input ng-click="checkUncheckTalk(talk._id,talk.Selected)" ng-model="talk.Selected" selected="{{talk.Selected}}" type="checkbox"></td>
<td>{{talk.title}}</td>
<td>{{talk.duration || 0 | timestring }}</td>
<td>{{bytesToMB(talk.size) || 0}} mb</td>
<td>${{talk.price || 0}}</td>
<td class="action-item">
<!-- <i class="fa fa-plus icon-gray"></i> -->
<a ng-click="openUpdateTalkModal('md',talk._id)" href="#"><i class="fa fa-pencil icon-gray" ></i></a>
<a ng-click="deleteTalk(talk._id)" href="javascript:void(0);"><i class="fa fa-trash icon-gray"></i></a>
</td>
</tr>
<tr>
<td colspan="6">
<div data-ng-if="totalTalkCount> 10" class="col-md-12">
<div pagination total-items="totalTalkCount"
ng-model="currentTalkPageNo"
max-size="maxSize"
class="pagination-sm pull-right"
boundary-links="true"
ng-change="talkPageChanged(currentSeriesId)"></div>
</div>
<div data-ng-if="totalTalkCount == 0" class="col-md-2">
<div>No record Found.</div>
</div>
</td>
</tr>
</tbody>
</table>
</div> <!-- end table one -->
</div>
<div class="col-md-12">
<div pagination total-items="totalItems"
ng-model="currentPage"
max-size="maxSize"
class="pagination-sm pull-right"
boundary-links="true"
ng-change="pageChanged()"></div>
</div>
And below controller code
//first it is working properly
vm.currentPage = 1;
vm.maxSize = 5;
vm.pageChanged = function () {
console.log('page changed:', vm.currentPage);
vm.getSeriesList();
//$scope.getMembers();
};
//second its not working
vm.currentTalkPageNo = 1;
vm.talkPaginate = false;
vm.talkPageChanged = function (seriesId) {
console.log('page talk changed:', vm.currentTalkPageNo);//each time it shows 1 page no
vm.talkPaginate = true;
vm.showTalks(seriesId);
//$scope.getMembers();
};
remove below code
data-ng-if="totalTalkCount == 0"
in pagination parent div to
data-ng-class="{ 'dn':totalTalkCount <= 10}"
And use
ng-model="$parent.currentTalkPageNo"
instead of
ng-model="currentTalkPageNo"
css
.dn{display:none;}

How to convert an existing table(Html) to jQuery datatable in AngularJS

Below is the html I have used to show data in the table, its working fine.
Now I want to convert it to jQuery Datatables.
HTML:-
<table cellpadding="3" class="table table-bordered">
<thead>
<tr class="success">
<th style="cursor: pointer;" ng-click="sort('DOB')"><b>DOB</b> <span class="glyphicon sort-icon" ng-show="sortKey=='DOB'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
<th style="cursor: pointer;" ng-click="sort('StateName')"><b>State</b> <span class="glyphicon sort-icon" ng-show="sortKey=='StateName'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
<th style="cursor: pointer;" ng-click="sort('FileId')"><b>Image</b> <span class="glyphicon sort-icon" ng-show="sortKey=='FileId'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<tr dir-paginate="employee in employees|orderBy:sortKey:reverse|filter:search|itemsPerPage:5" ng-model="search">
<td>{{employee.DOB | date:'MM/dd/yyyy' }}
<td>{{employee.StateName}}
</td>
<td>
<img ng-src="UploadedFiles/{{employee.FilePath}}" class="img-circle" style="max-width: 50px" alt='Employee Image Missing' />
</td>
</tr>
</tbody>
</table>

Resources