javascript - Selected cells is not permanent when redraw table -
i have table:
<style> table .highlighted { background-color: #999; } table .unhighlighted { background-color: whitesmoke; } </style> <form> <div class="form-group"> <div class="input-group"> <div class="input-group-addon"> <i class="fa fa-search"></i> </div> <input type="text" class="form-control" placeholder="aramak İstediğiniz Ürün alanını giriniz" ng-model="src_product"> </div> </div> </form> </div> <div class="row"> <div class="col-md-10"> <br/> <table ng-table="userstable" id="producttable" class="table table-striped"> <tr> <th ng-repeat="column in cols">{{column}}</th> <th> adet</th> </tr> <tr ng-repeat="row in data | filter: src_product"> <td class="unhighlighted" ng-click="selectcell(this)" ng-repeat="column in cols ">{{row[column]}}</td> <td><input class="input-group" type="text" style="width: 100%; height: 30px !important" name=" adet" value="0"></td> </tr> </table> </div> </div>
and javascript file:
myapp.controller('productcontroller', ['$rootscope', '$scope', 'shareddataservice', "productfactory", "$log", "$filter", 'ngtableparams', function ($rootscope, $scope, shareddataservice, productfactory, $log, $filter, ngtableparams) { $scope.users = [{"id":1,"first_name":"philip","last_name":"kim","email":"pkim0@mediafire.com","country":"indonesia","ip_address":"29.107.35.8"}, {"id":2,"first_name":"judith","last_name":"austin","email":"jaustin1@mapquest.com","country":"china","ip_address":"173.65.94.30"}, {"id":3,"first_name":"julie","last_name":"wells","email":"jwells2@illinois.edu","country":"finland","ip_address":"9.100.80.145"}, {"id":4,"first_name":"gloria","last_name":"greene","email":"ggreene3@blogs.com","country":"indonesia","ip_address":"69.115.85.157"}, {"id":50,"first_name":"andrea","last_name":"greene","email":"agreene4@fda.gov","country":"russia","ip_address":"128.72.13.52"},{"id":1,"first_name":"philip","last_name":"kim","email":"pkim0@mediafire.com","country":"indonesia","ip_address":"29.107.35.8"}, {"id":2,"first_name":"judith","last_name":"austin","email":"jaustin1@mapquest.com","country":"china","ip_address":"173.65.94.30"}, {"id":3,"first_name":"julie","last_name":"wells","email":"jwells2@illinois.edu","country":"finland","ip_address":"9.100.80.145"}, {"id":4,"first_name":"gloria","last_name":"greene","email":"ggreene3@blogs.com","country":"indonesia","ip_address":"69.115.85.157"}, { "id": 50, "first_name": "andrea", "last_name": "greene", "email": "agreene4@fda.gov", "country": "russia", "ip_address": "128.72.13.52" }, { "id": 1, "first_name": "philip", "last_name": "kim", "email": "pkim0@mediafire.com", "country": "indonesia", "ip_address": "29.107.35.8" }, { "id": 2, "first_name": "judith", "last_name": "austin", "email": "jaustin1@mapquest.com", "country": "china", "ip_address": "173.65.94.30" }, { "id": 3, "first_name": "julie", "last_name": "wells", "email": "jwells2@illinois.edu", "country": "finland", "ip_address": "9.100.80.145" }, { "id": 4, "first_name": "gloria", "last_name": "greene", "email": "ggreene3@blogs.com", "country": "indonesia", "ip_address": "69.115.85.157" }, { "id": 50, "first_name": "andrea", "last_name": "greene", "email": "agreene4@fda.gov", "country": "russia", "ip_address": "128.72.13.52" }]; $scope.userstable = new ngtableparams({ page: 1, count: 10 }, { total: $scope.users.length, getdata: function ($defer, params) { //this redrawing part $scope.data = params.sorting() ? $filter('orderby')($scope.users, params.orderby()) : $scope.users; $scope.data = params.filter() ? $filter('filter')($scope.data, params.filter()) : $scope.data; $scope.data = $scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count()); $defer.resolve($scope.data); } }); $scope.cols = object.keys($scope.users[0]); $scope.src_product = ''; $scope.cell = ""; $scope.selectcell = function (cell) { // var den = object.keys($scope.users[0])[4]; var selectedcellindex = (cell.$index) + (cell.$parent.$index) * ($scope.cols.length + 1); var selectedcell = document.getelementsbytagname("td")[selectedcellindex]; if (selectedcell.getattribute("class") === null) { selectedcell.setattribute("class", "highlighted"); } else { selectedcell.removeattribute("class"); } } }]);
i can select multiple cells when click page or search , table redrawn , selected cells turn unhighligted. how can fix without changes on users array?
Comments
Post a Comment