I have factory, that send request to get some data. After responce, i will receive it in controller and create scope list. Than i must to filter this list by checking checkboxes. I'v receive results, but they not visible. Help me pls...
$scope.checkRooms = [];
$scope.filterRooms = function(app) {
return function(p) {
for (var i in $scope.checkRooms) {
if (p.rooms == $scope.uniqueRooms[i] && $scope.checkRooms[i]) {
return true;
}
}
};
};
UPDATE 2
Here is working fiddle . Now how to sort by ASC rooms numbers? "orderBy" function sort correct but rooms indexes sort wrong
Ok here's a slightly different approach whereby the filtering is done in the controller rather than using the filter:expression in your ng-repeat.
Not the only way to do it but I think you should definitely think about removing any watch functions from your controllers they make it really difficult to test your controllers.
Fiddle
HTML
<div class="filter-wrap" ng-controller="mainController">
<div class="main-filter">
<div class="form-group">
<span class="gr-head">
Rooms count
</span>
<div class="check-control" ng-repeat="room in uniqueRooms | orderBy: room">
<input
type="checkbox"
name="room_cnt"
ng-model="checkboxes[room]"
ng-change='onChecked(filterRoom)'
/>
<label>{{room}}</label>
</div>
</div>
</div>
<table>
<thead>
<tr>
<th>
<span>Rooms</span>
</th>
<th>
<span>Size</span>
</th>
<th>
<span>Price</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="app in filteredApps">
<td>{{app.rooms}}</td>
<td>{{app.size}}</td>
<td>{{app.price}}</td>
</tr>
</tbody>
</table>
<div class="result">
<h2>SCOPE size</h2>
{{filteredRooms}}
</div>
</div>
JS
var sortApp = angular.module('sortApp',[]);
sortApp.controller('mainController', function($scope, $timeout) {
$scope.apps = [
{
"rooms": 2,
"size": 55.50,
"price": 55500.00,
},
{
"rooms": 1,
"size": 25.50,
"price": 45000.00,
},
{
"rooms": 8,
"size": 28,
"price": 15500.00,
},
{
"rooms": 1,
"size": 28,
"price": 15500.00,
},
{
"rooms": 8,
"size": 28,
"price": 15500.00,
},
{
"rooms": 3,
"size": 120.55,
"price": 88990.00,
},
{
"rooms": 3,
"size": 120.55,
"price": 88990.00,
}
];
$scope.filteredApps = $scope.apps;
$scope.uniqueRooms = uniqueItems($scope.apps, 'rooms');
$scope.onChecked = filterRooms;
$scope.checkboxes = createCheckboxes($scope.uniqueRooms);
function filterRooms(checkboxes){
$scope.filteredApps = [];
angular.forEach($scope.apps, function(app){
if($scope.checkboxes[app.rooms]){
$scope.filteredApps.push(app);
}
});
}
function createCheckboxes(labels){
var checkboxes = {};
angular.forEach(labels, function(label){
checkboxes[label] = true;
});
return checkboxes;
}
function uniqueItems(data, key) {
var result = [];
for (var i = 0; i < data.length; i++) {
var value = data[i][key];
if (result.indexOf(value) == -1) {
result.push(value);
}
}
return result;
};
});
Related
I'm trying to setup hotkeys for an old project that still uses angular 1.x and one of the features I was trying to add would be to select the first row from a table that is created with an NG-REPEAT. I've been able to add in other functionality such has moving the selected row up / down because I pass in the selected row on ng-click="setSelected(this)" which then lets me save the row and move it with selectedRow.$$prevSibiling or selectedRow.$$nextSibiling.
What I'm having a hard time figuring out is how can I set the selectedRow from the controller.
Here is a quick example:
http://plnkr.co/edit/6jPHlYwkgF5raRWt?open=lib%2Fscript.js
JS:
App.controller('ActivitiesCtrl', [function() {
var vm = this;
vm.selectedRow = "Not set";
vm.activities = [
{
"id": 1,
"code": "ABC",
"person": "Joe"
},
{
"id": 2,
"code": "DFF",
"person": "Sally"
},
{
"id": 3,
"code": "ABC",
"person": "Sue"
},
{
"id": 4,
"code": "124",
"person": "Sam"
},
];
vm.setSelected = function(row) {
vm.selectedRow.selected = false;
vm.selectedRow = row;
vm.selectedRow.selected = true;
}
vm.moveNext = function() {
vm.setSelected(vm.selectedRow.$$nextSibling)
}
vm.setFirst = function() {
vm.setSelected("How do I set it...");
// How to set it? vm.setSelected(?????)
}
}]);
HTML:
<div ng-controller="ActivitiesCtrl as vm">
<table>
<thead>
<th>Id</th>
<th>Code</th>
<th>Person</th>
</thead>
<tbody>
<tr ng-repeat="activity in vm.activities track by activity.id" ng-click="vm.setSelected(this)" ng-class="{info: selected}">
<td>{{activity.id}}</td>
<td>{{activity.code}}</td>
<td>{{activity.person}}</td>
</tr>
</tbody>
</table>
{{vm.selectedRow | json}}
<hr />
<button ng-click="vm.setFirst()">Set First</button>
<button ng-click="vm.moveNext()">Next</button>
</div>
You can do this by setting the actual object from the array as selectedRow rather than using this and set the class by checking if selectedRow === activity in the ng-class.
This approach doesn't require mutating the objects
<tr
ng-repeat="activity in vm.activities track by activity.id"
ng-click="vm.setSelected(activity)"
ng-class="{info: vm.selectedRow == activity}"
>
Then you can use Array#findIndex() to get the current selectedRow index in the array and if a next one exists use it or go back to the first.
For the setFirst() you just use vm.activities[0]
vm.selectedRow = null;
vm.setSelected = function (row) {
vm.selectedRow = row;
};
vm.moveNext = function () {
const {selectedRow:curr, activities:act} = vm;
if (curr !== null) {
let idx = act.findIndex(e => e == curr) + 1;
let next = act[idx] || act[0];
vm.setSelected(next);
}
};
vm.setFirst = function () {
vm.setSelected(vm.activities[0]);
};
Working plunker
Here is the link with test working example.
enter code here
http://plnkr.co/edit/7mTvRB0ZlHOQwOIc?preview
I have an array with objects with 'SALARY' field. I want to manage 'CREDIT' amount using ng-model. so i am create a function and work fine with object id. but in my case when i am change value of any input field it is change all input's values.
Please any one tell me how to possible change input value only desire input field.
this is my html >
<div ng-repeat="obj in myObj">
{{obj.id}} /
{{obj.name}} /
{{obj.salary}} /
<input type="text" ng-model="credit.amount" />
<button ng-click="updateBalance(obj)">Balance</button>
</div>
and this is my script >
var app = angular.module('myApp',[]);
app.controller('employee', function($scope) {
$scope.myObj = [
{ "id" : 1, "name" : "abc", "salary" : 10000 },
{ "id" : 2, "name" : "xyz", "salary" : 15000 }
]
$scope.credit = {"amount" : 0};
$scope.updateBalance = function(obj){
console.log(obj.name + "'s current balance is : ");
console.log(obj.salary - Number($scope.credit.amount));
}
});
and this is my PLNKR LINK.
Values in all input fields are changing because you are binding $scope.credit.amount to all of them. Instead you need to maintain them separately. Following should work:
Html
<tr ng-repeat="obj in myObj">
<td>{{obj.id}} </td>
<td>{{obj.name}} </td>
<td>{{obj.salary}} </td>
<td>
<input type="number" ng-model="credits[obj.id].amount" />
</td>
<td>
<button ng-click="updateBalance(obj)">Balance</button>
</td>
</tr>
Controller
var app = angular.module('myApp', []);
app.controller('employee', function($scope) {
$scope.myObj = [{
"id": 1,
"name": "abc",
"salary": 10000
}, {
"id": 2,
"name": "xyz",
"salary": 15000
}]
$scope.credits = $scope.myObj.reduce(function(acc, object) {
acc[object.id] = { amount: 0 };
return acc;
}, {});
$scope.updateBalance = function(obj) {
var balance = obj.salary - Number($scope.credits[obj.id].amount)
alert(obj.name + ' balance is : ' + balance);
}
});
First, here is all the code that leads me to the error I'm getting:
The JSON:
[
{
"Id": 0,
"UserName": "uniqueusername",
"Photo": "base64string",
"Email": "user#user.com",
"Office": "Location "
},
{
"Id": 1,
"UserName": "uniqueusername",
"Photo": "base64string",
"Email": "user#user.com",
"Office": "Location"
},
{
"Id": 2,
"UserName": "uniqueusername",
"Photo": "base64string",
"Email": "user#user.com",
"Office": "Location"
},
{
"Id": 3,
"UserName": "uniqueusername",
"Photo": "base64string",
"Email": "user#user.com",
"Office": "Location"
},
{
"Id": 4,
"UserName": "uniqueusername",
"Photo": "base64string",
"Email": "user#user.com",
"Office": "Location"
}
]
It is generated using this function in my controller:
List<string> Names = arepo.GetAllAvionteUsers();
List<UserPreviewViewModel> AllUsers = new List<UserPreviewViewModel>();
int count = 0;
foreach(string name in Names)
{
UserPreviewViewModel preview = new UserPreviewViewModel(name);
preview.Id = count;
AllUsers.Add(preview);
count++;
if (count == 10) break;
}
return Json(new { Users = JsonConvert.SerializeObject(AllUsers, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore}) }, JsonRequestBehavior.AllowGet);
The View Model:
public int Id { get; set; }
public string UserName { get; set; }
public string Photo { get; set; }
public string Email { get; set; }
public string Office { get; set; }
the angular controller:
angular.module('app.module')
.factory('Users', ['$http', function UsersFactory($http) {
return {
AllUsers: function () {
return $http({ method: 'GET', url: '/Controller/GetAllUsers' });
}
}
}]);
angular.module('app.module')
.controller('UserController', ['$scope', 'Users', function ($scope, Users) {
var vm = this;
Users.AllUsers().success(function (data) {
vm.users = JSON.stringify(data.Users);
});
}]);
And finally the view:
<table class="dataTable row-border hover" datatable="ng" dt-instance="vm.dtInstance"
dt-options="vm.dtOptions">
<thead>
<tr>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">Id</span>
</div>
</th>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">Name</span>
</div>
</th>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">Photo</span>
</div>
</th>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">Email</span>
</div>
</th>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">Office</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in vm.users">
<td>{{user.Id}}</td>
<td>{{user.UserName}}</td>
<td><img class="product-image" ng-src="data:img/jpg;base64,{{user.Photo}}"></td>
<td>{{user.EmailAddress}}</td>
<td>{{user.Office}}</td>
</tr>
</tbody>
</table>
Every time that I try to run this code I get the following error from my JSON:
angular.js:13920 Error: [ngRepeat:dupes] Duplicates in a repeater are
not allowed. Use 'track by' expression to specify unique keys.
Repeater: user in vm.users, Duplicate key: string:\, Duplicate value:
\
I have tried to use angular's suggested fix, which is track by $index and all that does is cause my page to freeze.
I have tried to take out the Formatting.Indented when I return the JSON string and all that does is give me the same error as well as taking out the ReferenceLoopHandling part and also getting the same error.
In the angular controller I tried to do JSON.parse(data) and I get the following error:
angular.js:13920 SyntaxError: Unexpected token o in JSON at position 1
When I try to do let users = data.Users and then do let count = users.length it gives me the number 85941 which seems like it is counting every single character in the string.
When I do a console.log(data) it gives me the JSON that I pasted above (I did change usernames, emails, and locations to keep my user's info safe).
At this point I have absolutely no clue what is wrong here or how to fix it, any help would be greatly appreciated.
Thanks!
Although I am not entirely sure as to why this error occurred in first place, the fix for it was not to return JSON from the controller. I modified my return statement like so:
return Json(JsonConvert.SerializeObject(AllUsers, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore}), JsonRequestBehavior.AllowGet);
Then in the angular controller i did:
vm.users = JSON.parse(data);
That gave me the proper JSON array and now it works perfectly.
I am aware that it may be Duplicate Question, but I tried that too but it didnt work it. So, I am posting my Question now. My Question is Apply the Date range filter using Angular js only one column.
Here is MY code:
HTML:
<div ng-app="myApp" ng-controller="myCtrl">
<div>
<table>
<tr>
<td>Start Date</td>
<td><input type="text" name="S_Date" ng-model="startDate"/></td>
<td>End Date</td>
<td><input type="text" name="E_Date" ng-model="endDate"/>
</tr>
</table>
</div>
<table>
<tr>
<th>Date</th>.
<th>Stock</th>
</tr>
<tr ng-repeat="subject in records |myfilter:startDate:endDate">
<td>{{ subject.name * 1000|date:'dd-MM-yyyy'}}<td>
<td>{{ subject.marks }}</td>
</tr>
</table>
Angular JS:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.records = [
{
"name" : "2016-08-01",
"marks" : 250
},{
"name" : "2016-08-02",
"marks" : 150
},{
"name" : "2016-08-03",
"marks" : 100
},{
"name" : "2016-08-04",
"marks" : 150
},{
"name" : "2016-05-01",
"marks" : 750
},{
"name" : "2016-05-02",
"marks" : 1500
},{
"name" : "2016-03-03",
"marks" : 500
},{
"name" : "2016-04-04",
"marks" : 650
}
]
function parseDate(input) {
var parts = input.split('-');
return new Date(parts[2], parts[1]-1, parts[0]);
}
app.filter("myfilter", function() {
return function(items, from1, to) {
var df = parseDate(from1);
var dt = parseDate(to);
alert(df)
alert(dt)
var result = [];
for (var i=0; i<items.length; i++){
var tf = new Date(items[i].startDate * 1000),
tt = new Date(items[i].endDate * 1000);
if (tf > df && tt < dt) {
result.push(items[i]);
}
}
return result;
};
});
});
</script>
Please advice me Where I am going wrong.Please suggest me.Thanks in advance.
I recommend you to use moment.js library: http://momentjs.com/
Here is working plunkr with your range filter: https://plnkr.co/edit/dfpsBI0uom5ZAEnDF3wM?p=info
<div ng-controller="MainCtrl">
<table>
<tr>
<td>Start Date</td>
<td>
<input type="text" name="S_Date" ng-model="startDate" />
</td>
<td>End Date</td>
<td>
<input type="text" name="E_Date" ng-model="endDate" />
</td>
</tr>
</table>
<table>
<tr>
<th>Date</th>.
<th>Stock</th>
</tr>
<tr ng-repeat="subject in records | myfilter: startDate: endDate">
<td>{{ subject.name | date:'dd-MM-yyyy'}}</td>
<td>{{ subject.marks }}</td>
</tr>
</table>
</div>
app.controller('MainCtrl', function($scope) {
$scope.startDate = "2016-08-01";
$scope.endDate = "2016-08-03";
$scope.records = [{
"name": "2016-08-01",
"marks": 250
}, {
"name": "2016-08-02",
"marks": 150
}, {
"name": "2016-08-03",
"marks": 100
}, {
"name": "2016-08-04",
"marks": 150
}, {
"name": "2016-05-01",
"marks": 750
}, {
"name": "2016-05-02",
"marks": 1500
}, {
"name": "2016-03-03",
"marks": 500
}, {
"name": "2016-04-04",
"marks": 650
}];
});
app.filter("myfilter", function($filter) {
return function(items, from, to) {
return $filter('filter')(items, "name", function(v) {
var date = moment(v);
return date >= moment(from) && date <= moment(to);
});
};
});
$scope.Customfilterobj`enter code here` = { status: "Complete",StartDate: "2017-02-01T08:00:00",EndDate: "2018-02-01T08:00:00 " };
<tr ng-repeat="dt in data | filter: {Status: Customfilterobj.status} | dateRange:Customfilterobj.StartDate:Customfilterobj.EndDate">
Here we have use two filters as below:
filter: {Status: Customfilterobj.status} work as compare "complete" value with Status of data collection.
dateRange:Customfilterobj.StartScheuleDate:Customfilterobj.EndScheuleDate" : dateRange is custom filter for compare Expiration_date between StartDate and EndDate.
app.filter('dateRange', function () {
return function (data, greaterThan, lowerThan) {
if (greaterThan != null && lowerThan != null && greaterThan != undefined && lowerThan != undefined) {
data = data.filter(function (item) {
if (item.Expiration_date != null) {
var exDate = new Date(item.Expiration_date);
return exDate >= new Date(greaterThan) && exDate <= new Date(lowerThan);
}
});
}
return data;
};
});
Adding off of Roman Koliada's plunker. His process has a small issue in the usage of the angular $filter. I have the updated here:
https://plnkr.co/edit/l4t4Fln4HhmZupbmOFki?p=preview
New filter:
app.filter("myfilter", function($filter) {
return function(items, from, to, dateField) {
startDate = moment(from);
endDate = moment(to);
return $filter('filter')(items, function(elem) {
var date = moment(elem[dateField]);
return date >= startDate && date <= endDate;
});
};
});
The issue was that the function input into $filter function was the third param, and loops over every attribute of every object in the list. Console logging his plunker calls moment() on every single attribute of every object. By instead inputting a function as the second param, as the expression instead of the comparator - we can call the comparison only on the date field.
Angular doc: https://docs.angularjs.org/api/ng/filter/filter
I created html table and used ng-repeat to show items in table,
but i can't select multiple rows in table.
How can achieve this by using control key
Thank you!
<div class="table_bg">
<table datatable="ng" dt-options="dtOptions" dt-column-defs="dtColumnDefs" class="table table-striped table-bordered dt-responsive nowrap res_table" cellspacing="0" width="100%">
<thead>
<tr>
<th>#</th>
<th>Description</th>
<th>Ali</th>
<th> Extension</th>
<th> Ext/th>
<th>Comp</th>
</tr>
</thead>
<tbody ng-hide="loading">
<tr ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow($index)" ng-repeat="docType in DocTypes" ng-cloak ng-mouseenter="hover(docType)" ng-mouseleave="hover(docType)">
<td>{{$index}}</td>
<td>
{{docType.Desc}}
</td>
<td>{{docType.LI}}</td>
<td>{{docType.Ext}}</td>
<td>{{docType.EXT}}</td>
<td>{{docType.Comp}}</td>
</tr>
</tbody>
</table>
I hope this is not too late for you, I have you answer.
You can use the $event.ctrlKey parameter to check if the user has pressed control.
Even better, there is a $event.shiftKey parameter to check if shift was pressed.
You can use it this way, (I let all the logic in a simple controller so that it is easier to understand but I advice you to put it inside a service).
Also I have chosen to store only the rows index but it works the same with full rows.
HTML
<tr ng-repeat="row in rows track by $index" ng-click="selectRow($event, $index)" ng-class="{highlitedRow: isRowSelected($index)}">
AngularJS
var selectedRowsIndexes = [];
$scope.rows = [{name: 'Happy Butterfly'}, {name: 'Wonderful Bee'}];
$scope.selectRow = function(event, rowIndex) {
if(event.ctrlKey) {
changeSelectionStatus(rowIndex);
} else if(event.shiftKey) {
selectWithShift(rowIndex);
} else {
selectedRowsIndexes = [rowIndex];
}
console.log(selectedRowsIndexes);
console.log(getSelectedRows());
console.log(getFirstSelectedRow());
};
function selectWithShift(rowIndex) {
var lastSelectedRowIndexInSelectedRowsList = selectedRowsIndexes.length - 1;
var lastSelectedRowIndex = selectedRowsIndexes[lastSelectedRowIndexInSelectedRowsList];
var selectFromIndex = Math.min(rowIndex, lastSelectedRowIndex);
var selectToIndex = Math.max(rowIndex, lastSelectedRowIndex);
selectRows(selectFromIndex, selectToIndex);
}
function getSelectedRows() {
var selectedRows = [];
angular.forEach(selectedRowsIndexes, function(rowIndex) {
selectedRows.push($scope.rows[rowIndex]);
});
return selectedRows;
}
function getFirstSelectedRow() {
var firstSelectedRowIndex = selectedRowsIndexes[0];
return $scope.rows[firstSelectedRowIndex];
}
function selectRows(selectFromIndex, selectToIndex) {
for(var rowToSelect = selectFromIndex; rowToSelect <= selectToIndex; rowToSelect++) {
select(rowToSelect);
}
}
function changeSelectionStatus(rowIndex) {
if($scope.isRowSelected(rowIndex)) {
unselect(rowIndex);
} else {
select(rowIndex);
}
}
function select(rowIndex) {
if(!$scope.isRowSelected(rowIndex)) {
selectedRowsIndexes.push(rowIndex)
}
}
function unselect(rowIndex) {
var rowIndexInSelectedRowsList = selectedRowsIndexes.indexOf(rowIndex);
var unselectOnlyOneRow = 1;
selectedRowsIndexes.splice(rowIndexInSelectedRowsList, unselectOnlyOneRow);
}
function resetSelection() {
selectedRowsIndexes = [];
}
$scope.isRowSelected = function(rowIndex) {
return selectedRowsIndexes.indexOf(rowIndex) > -1;
};
});
Last thing, if you want to use powerfull tables, I recommend you ng-table.
If you use ng-table, be sure to add
$scope.$on('ngTableAfterReloadData', function() {
resetSelection();
});
and replace $scope.rows[rowIndex] with $scope.tableParams.data[rowIndex]
In this sample i try to detect which row is selected, so i add selected param to the each object which already selected, and then we can use $filter to detect the selected rows.
var app = angular.module("app", []);
app.controller("ctrl", function($scope, $filter) {
$scope.users = [{
name: "x"
}, {
name: "y"
}, {
name: "z"
}];
$scope.selectedRows = [];
$scope.select = function(item) {
item.selected ? item.selected = false : item.selected = true;
}
$scope.getAllSelectedRows = function() {
var selectedRows = $filter("filter")($scope.users, {
selected: true
}, true);
$scope.selectedRows = selectedRows;
}
});
body {
padding-top: 50px;
}
tr td {
cursor: pointer
}
tr.selected td {
background: #ccc!important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div ng-app="app" ng-controller="ctrl">
<div class="container">
<table class="table table-bordered">
<tr ng-repeat="user in users" ng-class="{'selected': user.selected}" ng-click="select(user)">
<td ng-bind="user.name" title="click to select a row"></td>
</tr>
</table>
<button class="btn btn-primary" ng-click="getAllSelectedRows()">Get All Selected Rows</button>
{{selectedRows | json}}
</div>
</div>
This demo uses Ctrl, Shift and combination of both for multiple selection of table rows in angularJs.
For plnkr demo.
http://plnkr.co/edit/IGBCkLpmK4ecJ9RUsALa?p=preview
Html goes like this
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="angular.js#*" data-semver="4.0.0" src="https://code.angularjs.org/latest/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="multiSelectController as vm">
{{vm.a}}
<table>
<thead>
</thead>
<tbody style="border:1px solid blue;">
<tr ng-repeat="item in vm.externalProductsTypes" ng-click="vm.selectUnselectMultiple($index,$event)" ng-class="{'selected': vm.isRowSelectedUnselect($index)}">
<td style="border:1px solid blue;">{{item.id}}</td>
<td style="border:1px solid blue;">
<div style="float:left; margin-right: 10px;">{{item.name}}</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
controller goes like this
var app = angular.module('app', []);
app.controller('multiSelectController', function() {
var vm = this;
/* Data loading */
vm.externalProductsTypes = [{
"id":1,
"name": "Access Winback"
}, {
"id":2,
"name": "ADSL",
}, {
"id":3,
"name": "Bigpond ADSL Activation",
}, {
"id":4,
"name": "Bigpond ADSL Recontracting",
}, {
"id":5,
"name": "Bigpond Cable Activation",
}, {
"id":6,
"name": "Bigpond Cable Recontracting",
}, {
"id":7,
"name": "Bigpond VAS",
}, {
"id":8,
"name": "Bigpond Wireless Activation",
}, {
"id":9,
"name": "Bigpond Wireless Recontracting",
}, {
"id":10,
"name": "Broadband Right Plan",
}];
/* click function */
vm.selectUnselectMultiple = function (idx, event) {
if (event.which != '1') {
return;
}
var row = vm.externalProductsTypes[idx];
row.rowIndex = idx;
if (!event.ctrlKey && !event.shiftKey) {
vm.clearAll();
vm.toggleRow(row);
vm.selectionPivot = row;
return;
}
if (event.ctrlKey && event.shiftKey) {
vm.selectRowsBetweenIndexes(vm.selectionPivot.rowIndex, row.rowIndex);
return;
}
if (event.ctrlKey) {
vm.toggleRow(row);
vm.selectionPivot = row;
}
if (event.shiftKey) {
vm.clearAll();
vm.selectRowsBetweenIndexes(vm.selectionPivot.rowIndex, row.rowIndex);
}
}
/* other supported functions */
vm.toggleRow = function (row) {
row.className = row.className == 's' ? '' : 's';
}
vm.selectRowsBetweenIndexes = function (ia, ib) {
var bot = Math.min(ia, ib);
var top = Math.max(ia, ib);
for (var i = bot; i <= top; i++) {
vm.externalProductsTypes[i].className = 's';
}
}
vm.clearAll = function () {
for (var i = 0; i < vm.externalProductsTypes.length; i++) {
vm.externalProductsTypes[i].className = '';
}
}
vm.isRowSelectedUnselect = function (index) {
if (vm.externalProductsTypes[index].className=='s') { // if found, then select the row.
return true;
}
}
});
finally the css for row selection
.selected {
background-color: steelblue !important;
color: white;
font-weight: bold;
}