angularjs - Trying to highlight multiple cells from table row but only 1 column getting highlighted? -
i have create table looks this
5 11 24 "" "" "" "" 71 88 "" "" 25 "" 42 53 61 "" 90 7 14 "" 32 50 "" 65 "" ""
i trying select multiple values it's not working. want if have selected number , going select should not remove previous one. tried store selected numbers in array , created method invoke ng-class ng-class calling without selecting number.
var ticktstr = $scope.ticketsdata; console.log(ticktstr); var ticketlist = []; var ticktrow = []; var gamedata = ticktstr[0]; angular.foreach(ticktstr, function(value, index) { var ticketobj = new object(); ticketobj.id = json.parse(value.ticket.id); ticketobj.ticket = json.parse(value.ticket.ticket); ticketobj.number = []; ticketlist.push(ticketobj); }); console.log(ticketlist); $scope.tickets = ticketlist; $scope.selectnumber=function(row,number){ var drawnnumberarray=[]; var ticketarray=[]; var obj={}; $scope.choosen=number; $scope.selectedticket=row; }
<table class="table table-bordered tickets-tbl" ng-repeat="ticketrow in tickets"> <tbody> <tr> <td class="tickets-tbl-td"> <table> <tr class="tckts" ng-repeat="row in ticketrow.ticket track $index"> <td ng-class="{selected: choosen == drawnnumber && row[0]==choosen && ticketrow.id == selectedticket}" ng-click="selectnumber(ticketrow.id,row[0])">{{row[0]}}</td> <td ng-class="{selected: choosen == drawnnumber && row[1]==choosen && ticketrow.id == selectedticket}" ng-click="selectnumber(ticketrow.id,row[1])" ">{{row[1]}}</td> <td ng-class="{selected: choosen==drawnnumber && row[2]==choosen && ticketrow.id==selectedticket} " ng-click="selectnumber(ticketrow.id,row[2]) "">{{row[2]}}</td> <td ng-class="{selected: choosen == drawnnumber && row[3]==choosen && ticketrow.id == selectedticket}" ng-click="selectnumber(ticketrow.id,row[3])" ">{{row[3]}}</td> <td ng-class="{selected: choosen== drawnnumber && row[4]==choosen && ticketrow.id==selectedticket} " ng-click="selectnumber(ticketrow.id,row[4]) "">{{row[4]}}</td> <td ng-class="{selected: choosen == drawnnumber && row[5]==choosen && ticketrow.id == selectedticket}" ng-click="selectnumber(ticketrow.id,row[5])" ">{{row[5]}}</td> <td ng-class="{selected: choosen==drawnnumber && row[6]==choosen && ticketrow.id==selectedticket} " ng-click="selectnumber(ticketrow.id,row[6]) "">{{row[6]}}</td> <td ng-class="{selected: choosen == drawnnumber && row[7]==choosen && ticketrow.id == selectedticket}" ng-click="selectnumber(ticketrow.id,row[7])" ">{{row[7]}}</td> <td ng-class="{selected: choosen==drawnnumber && row[8]==choosen && ticketrow.id==selectedticket} " ng-click="selectnumber(ticketrow.id,row[8]) "">{{row[8]}}</td> </tr> </table> </td> </tr> </tbody> </table>
i using ng-class highlight selected number.
response getting server
$scope.ticketsdata= [{ "id": 1, "ticket": "[[\"5\",\"11\",\"24\",null,null,null,null,\"71\",\"88\"],[null,null,\"25\",null,\"42\",\"53\",\"61\",null,\"90\"],[\"7\",\"14\",null,\"32\",\"50\",null,\"65\",null,null]]" }, { "id": 2, "ticket": "[[\"1\",null,null,null,\"44\",null,\"61\",\"71\",\"82\"],[\"4\",\"19\",\"22\",null,null,null,\"68\",\"76\",null],[null,null,\"30\",\"34\",\"50\",\"58\",null,null,\"83\"]]" }];
here code
angular.module('app', []).controller('ctrl', ['$scope', function($scope){ var ticketsdata= [{ "id": 1, "ticket": "[[\"5\",\"11\",\"24\",null,null,null,null,\"71\",\"88\"],[null,null,\"25\",null,\"42\",\"53\",\"61\",null,\"90\"],[\"7\",\"14\",null,\"32\",\"50\",null,\"65\",null,null]]" }, { "id": 2, "ticket": "[[\"1\",null,null,null,\"44\",null,\"61\",\"71\",\"82\"],[\"4\",\"19\",\"22\",null,null,null,\"68\",\"76\",null],[null,null,\"30\",\"34\",\"50\",\"58\",null,null,\"83\"]]" }]; $scope.tables = ticketsdata.map(function(x){ return { id: x.id, rows: json.parse(x.ticket)};}); $scope.selected = []; $scope.select = function(tableid, parentindex, index){ var selected = $scope.iselected(tableid, parentindex, index); if(!selected) $scope.selected.push({tableid, parentindex, index}); else $scope.selected.splice(selected, 1); } $scope.iselected = function(tableid, parentindex, index){ return $scope.selected.filter(function(x){ return x.tableid==tableid && x.parentindex==parentindex && x.index==index;})[0]; } }])
table { border-collapse: collapse; } table, td { border: 1px solid black; cursor: pointer; } .selected{ background-color:red }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app='app' ng-controller='ctrl'> <table ng-repeat='table in tables' style='margin-bottom:30px'> <tbody> <tr ng-repeat='row in table.rows' ng-init='$parentindex = $index'> <td ng-class='{selected:iselected(table.id, $parentindex, $index)}' ng-repeat='cell in row track $index' ng-click='select(table.id, $parentindex, $index)'>{{cell == null ? "\"\"" : cell}}</td> </tr> </tbody> </table> {{selected | json}} </div>
wiki
Comments
Post a Comment