javascript - can't load an array to ngTable -
i tried write small , simple ngtable demo, got problem:
when try put array ngtable, browser shows head line of table, not data. result in screenshot:
all code in plunker
here "data":
var books = [ { "name": "html start give up", "price": 2, "comment": "an awesome book pillow", "available": true }, { "name": "angularjs start give up", "price": 2, "comment": "too hard pillow", "available": false }];
and here way created ngtable
vm.booktable = createtable(books); var initpagesize = number(localstorage.getitem('page_size') || 20); vm.pagesize = initpagesize; vm.pagesizes = [10,20,30,50,100]; function createtable(data){ var initparams = { sorting: {name: "asc"}, count: vm.pagesize }; var initsettings = { counts: [], paginationmaxblocks: 13, paginationminblocks: 2, dataset: data }; return new ngtableparams(initparams, initsettings); }
and here part of html:
<body ng-controller="mycontroller vm"> <div> <table ng-table= "vm.booktable" class = "table" show-filter="true"> <tr ng-repeat="row in $data"> <td title = "'name'" filter="{name: 'text'}" sortable="'name'"> {{row.name}} </td> <td title = "'price'" filter="{price: 'number'}" sortable="'price'"> {{row.price}} </td> <td title = "'comment'" filter="{comment: 'number'}" sortable="'comment'"> {{row.count}} </td> </tr> </table> </div> <p>hello {{vm.name}}!</p> </body>
your error call createtable
function before set initpagesize
initparams.counts
undefined
you have put lines before call createtable
var initpagesize = number(localstorage.getitem('page_size') || 20); vm.pagesize = initpagesize; vm.pagesizes = [10,20,30,50,100];
here have working plunker.
Comments
Post a Comment