I'm using angular ng-grid like in this example: http://plnkr.co/edit/50vJrs?p=preview
But I need to load with a new URL the grid when I click for example on the button "reload".
How can I do that?
I'm using angular ng-grid like in this example: http://plnkr.co/edit/50vJrs?p=preview
But I need to load with a new URL the grid when I click for example on the button "reload".
How can I do that?
Define the url in scope variable:
$scope.source="largeLoad.json";
Use this URL in your getPagedDataAsync function instead of an hardcoded source.
$scope.getPagedDataAsync = function (pageSize, page, searchText) {
setTimeout(function () {
var data;
if (searchText) {
var ft = searchText.toLowerCase();
$http.get($scope.source).success(function (largeLoad) {
data = largeLoad.filter(function(item) {
return JSON.stringify(item).toLowerCase().indexOf(ft) != -1;
});
$scope.setPagingData(data,page,pageSize);
});
} else {
$http.get($scope.source).success(function (largeLoad) {
$scope.setPagingData(largeLoad,page,pageSize);
});
}
}, 100);
};
Finaly on reload change the source and call getPagedDataAsync again.
$scope.reload=function(){
$scope.source="largeLoad2.Json";
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, 1);
};
See this Plunker
Modify your getPagedDataAsync function to take a url parameter. Then you can specify which url to load data from.
$scope.getPagedDataAsync = function (url, pageSize, page, searchText) {
Inside the function you can get the data from the url parameter instead of the hardcoded value.
$http.get(url)
Now you can create a reload() function that calls getPagedDataAsync with a new url, and wire it up to a button.