javascript - Passing java script function result to Angular ng-table -


i have angular ng-table load json data $data variable , display in table.

function ngtable(){ var app = angular.module('main', ['ngtable']). controller('democtrl', function($scope, ngtableparams) {     var data = [{name: "moroni", age: 50},                 {name: "tiancum", age: 43},                 {name: "jacob", age: 27},                 {name: "nephi", age: 29},                 {name: "enos", age: 34},                 {name: "tiancum", age: 43},                 {name: "jacob", age: 27},                 {name: "nephi", age: 29},                 {name: "enos", age: 34},                 {name: "tiancum", age: 43},                 {name: "jacob", age: 27},                 {name: "nephi", age: 29},                 {name: "enos", age: 34},                 {name: "tiancum", age: 43},                 {name: "jacob", age: 27},                 {name: "nephi", age: 29},                 {name: "enos", age: 34}];      $scope.tableparams = new ngtableparams({         page: 1,            // show first page         count: 10           // count per page     }, {         total: data.length, // length of data         getdata: function($defer, params) {             $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));         }     }); }); } 

additionally have java script function returning other json data - function called on button click.

function returnjson() {  var json = [];   $('body').on('click','button#test', function(){    var id = $(this).attr("value").val();    json = id;   });  return json; } 

how replace var data content returnjson() every time on button click action ?

simple assignment work, remember reload grid:

$scope.loaddata = function () {   $scope.data = $scope.returnjson();   $scope.tableparams.reload(); }  $scope.returnjson = function () {   var json = [{name: "bb", age: 200},{name: "aaa", age: 100}];   return json; } 

here working demo: http://plnkr.co/edit/jw41ucmhgafjkuoliqor?p=preview


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -