Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload table on specific page #160

Closed
brunoaduarte opened this issue Aug 31, 2015 · 12 comments
Closed

Reload table on specific page #160

brunoaduarte opened this issue Aug 31, 2015 · 12 comments

Comments

@brunoaduarte
Copy link

Hello, i'm using the server side table:

<div tasty-table bind-resource-callback="getResource" bind-init="init" bind-filters="filterBy"> ...
</div>

How do i reload the table to a specific page after removing some item at that page (eg. page 5) ?
Here's how i reload the table:

$scope.filterBy.changeDetector = !$scope.filterBy.changeDetector;

but it always goes to page 1.

i've tried setting $scope.init.page to the last page number before changing the filterBy.changeDetector, but nothing happened.

Thanks !

@Zizzamia Zizzamia added this to the Version 0.5.9 milestone Sep 3, 2015
@thiagofmam
Copy link

I got the same bug. Do you have any fix?

@Zizzamia
Copy link
Owner

Zizzamia commented Sep 8, 2015

So, usually the page return to 1 when a filter is applied to the table, because by filtering something you will probably have less or more stuff to show. As default will always go back to 1.

What you instead guys want, is keeping the same page or the last possible available if the you filter the table in some way.

Am I understood correctly? Because if is like that, we need make some sort of API feature to turn on and off this special case.

@Zizzamia Zizzamia self-assigned this Sep 8, 2015
@thiagofmam
Copy link

I'd like use the last params used at the getResource and stay on the page what register was edited. How I had to change the filterBy to force the update, the params reset to page 1.

@thiagofmam
Copy link

Could I change the params used at getResource or reload the table without change the filterBy?

@thiagofmam
Copy link

I created two property and update the method. Now it work. I need add to filterBy the params: page and reloadTable;

Code:

 updateServerSideResource = function (updateFrom, newValue, oldValue) {
      if (updateFrom === 'filters') {
          var resetPage = false;
          var hasBreak = false;
          var hasNewproperty = true;
          if (newValue.page) {
              for (var oldproperty in oldValue) {
                  if (oldproperty === 'reloadTable' || oldproperty === "page") {
                      continue;
                  }
                  for (var newproperty in newValue) {
                      if (newproperty === 'reloadTable' || newproperty === "page") {
                          continue;
                      }
                      if (oldproperty === newproperty) {
                          hasNewproperty = false;
                          if (oldValue[oldproperty] !== newValue[newproperty]) {
                              resetPage = true;
                              hasBreak = true;
                          }
                          break;
                      }
                  }
                  if (hasNewproperty) {
                      resetPage = true;
                      break;
                  }
                  hasNewproperty = true;
                  if (hasBreak) {
                      break;
                  }
              }
          } else {
              resetPage = true;
          }
          if (resetPage) {
              $scope.params['page'] = 1;
          } else {
              $scope.params['page'] = $scope.params.page;
          }

      }
    $scope.url = buildUrl($scope.params, $scope.filters);
    if ($scope.reload) {
      $scope.reload = function () {
        $scope.resourceCallback($scope.url, angular.copy($scope.params))
        .then(function (resource) {
          setDirectivesValues(resource);
        });
      };
    }
    if (initNow || updateFrom === 'params') {
      var paramsObj = angular.copy($scope.params);
      paramsObj.filters = $scope.filters;
      $scope.resourceCallback($scope.url, paramsObj)
      .then(function (resource) {
        setDirectivesValues(resource);
      });
    }
  };

Thank you.

@vizog
Copy link

vizog commented Sep 12, 2015

What you instead guys want, is keeping the same page or the last possible available if the you filter the table in some way.

@Zizzamia Yes that's exactly what I need. As another example suppose that there is a refresh button on top of table which reloads the table using the same parameters.

@yywmrz
Copy link

yywmrz commented Dec 11, 2015

Where i can find the version 0.5.9 ?I just encounter the same problem

@yywmrz
Copy link

yywmrz commented Dec 11, 2015

i am a new guy who use github . i can't understand the content verywell cause English is not my mother language . Sorry

Zizzamia added a commit that referenced this issue Dec 14, 2015
@Zizzamia
Copy link
Owner

I create a new option name filterBase inside the init object, for use it you just need do this

$scope.init = {
    'count': 5,
    'page': 1,
    'sortBy': 'name',
    'sortOrder': 'dsc',
    'filterBase': 1
  };

if you set filterBase to false you will disable the auto reset to a specific page, and will be showed the old one or the last possible useful one.

Happy Holidays, and many thanks to push it hard on this. 😄
✨✨✨

@smargovsky
Copy link

👍

@Zizzamia
Copy link
Owner

Also just release on bower the version 0.5.9 with this fix in it!

@thiagofmam
Copy link

Thank you so much!

Happy Holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants