1

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?

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Jerrad was faster. His answer is basically the same as mine.
1

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.

Plunker demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.