I have a table that I auto-increment each row with based on the user's selection.
The problem I am faced with is ng-repeat copies the column I cannot differentiate between them. For example, each cell in the column is numbered the same using index. I would like to have a way of identifying where the user clicks on the cell.
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Sales</th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Service</th>
<th style="table-layout:fixed; text-align: center;" scope="col" colspan="2">Accounting</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Parts</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Body Shop</th>
<th style="vertical-align:top; text-align: center;" scope="col" colspan="2">Other</th>
</tr>
<tr>
<th></th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">Start</th>
<th class="start-end-time" style="text-align: center; font-size: .9em; color: #999;">End</th>
</tr>
</thead>
<tr ng-repeat="time in times">
<td>{{weekdays[$index]}}</td>
<td class="start-end-time" updated-row ng-repeat-start="(key,dept) in time" data-index="{{[key]}} start" editable-field time="dept.start"></td>
<td class="start-end-time" updated-row="{{$index}}" data-index="{{[key]}}" ng-repeat-end editable-field time="dept.end"></td>
<!-- {{times[$index][key].start}} -->
Monday Service start time {{times[0] |date: "shortTime"}}
<!-- <div id="HoursTable" newtable></div> -->
My controller
pp.controller('main', ['$scope', '$location', function($scope, $location) {
$scope.times = [];
$scope.timeArr = [];
$scope.timeObj = {};
$scope.clickedIndex;
$scope.departments = ["sales", "service", 'accounting', 'parts', 'bodyShop', 'other'];
$scope.weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
$.each($scope.weekdays, function(index, value) {
var dayTimes = {};
$.each($scope.departments, function(index, value) {
dayTimes[value] = {
start: '',
end: ''
};
});
$scope.times.push(dayTimes);
});
}]);
I have tried to create a data attribute called data-index="{{$index+=1}}"
Hopefully, my example makes a bit of sense. In a nutshell, I would need to give each cell in a column a identifier. As it is now, they all have the same value which stops me from applying any conditional logic.
<-- Updated -->
Located in the hours table page
ng-init="number = countInit()"
controller I added this piece of code as well:
$scope.countInit = function() {
return $scope.totalCount++;
}
When I try to display the results in my table using this syntax data-index={{number}}
My results are empty. How can this be? I almost feel like Angular is playing a practical joke on me. Or it could be my ignorance. I prefer to believe the former.
I thought my solution would work. Wondering where I have gone wrong. Can any humble soul help me?
Have you tried Angular-datatables? Your html markup for the table looks a bit broken. Angular-datatables took me a while to understand and to wire up but definitely worth the effort, you simply build your JSON data the way you want it and load it into Angular-datatables, the table structure is then generated for you.
Want pagination? or export to PDF/Excel? or you want to search the table or sort it? You still have a lot of work to do before you come close to this library. Here is some of my Angular-datatables code I use to inject a table into the DOM:
And here is my Factory to configure the options for my DataTables (Took me hours to gather all the options, there are many, and to get this exactly the way I like it! (Internet say 'Thank you!')
You can simply do like this,
This is the simplest way to use index with angular datatable.