javascript - Pagination with AngularJS or JS on object string or array -


i'm struggling implement pagination on developer's existing code. i've tried implementing of solutions explained in previous post: pagination on list using ng-repeat

the code takes two-dimensional array, parses through converting object of strings, , displays on page. each object key used column.

not sure how utilize angular's builtin limit filter setup. i think ideal solution. i'm open js solution well. (i've started out js solution below towards bottom of post.)

var data = [["c1","blah","yup","halted","bacon", "blue"],             ["c2","blank","everything","nothing test"],             ["c3","test","vista","xp, 7 "],             ["c4","true"],             ["c5","do","something else long text", "and more"]         ]  $rootscope.resultsobject = parseresults(data);  var columnsize = ["twelve", "six", "four", "three", "two", "two"]  $rootscope.columncountshow = columnsize[columncounter($rootscope.resultsobject)-1]  factory('parseresults', function(){         return function(resultsdata){             var resultsobject = {};             var column;             for(var = 0; resultsdata.length > i; i++){                 column = "column" +i;                 resultsobject[column] = resultsdata[i].tostring().replace(/[\,]/g, "<br>")             }             return resultsobject;         }     }) 

html:

<div class="{{columncountshow}} columns results-column" ng-repeat="resultsobject in resultsobject">         <div ng-bind-html-unsafe="resultsobject"> </div> 

how go doing show more style of pagination? it'll go through , display first 2 results each array, click show more, , loads next 2, etc.

the current method i'm using try , this: take data (before parsed) , slice off section, , parse bit. when select show more, it'll take next few lines, etc.

    var limit = 3;     var start = 0;     (var = 0; < data.length; i++) {         var ndata = [[]];         ndata = data[i].slice(start,limit);         console.log(ndata);     } 

issue this, seems thatdata remains intact. slice doesn't seem remove portion array?

update

slice not working out me. realized js has splice method. (for reason didn't think existed. current way of splicing data is:

$scope.submitwords = function(){         event.preventdefault();         var columncount = columncounter($scope.keywords);         var sendobject = keywordsplit($scope.keywords, columncount)          var limit = 2;         var start = 0;         var ndata = [[]];         (var = 0; < $scope.testdata.length; i++) {             ndata[i] = $scope.testdata[i].splice(start,limit);             console.log(ndata);             console.log("original data <br>" + $scope.testdata);         $rootscope.resultsobject = parseresults(ndata);         }         var columnsize = ["twelve", "six", "four", "three", "two", "two"];         $rootscope.columncountshow = columnsize[columncounter($rootscope.resultsobject)-1];     } 

this correctly splits data. need have updating model. when selecting show_more() replaces existing data rather appending it.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -