angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

Maintain table when changing between views

Open rszczypka opened this issue 11 years ago • 2 comments

First, thanks for the great plugin. I'm using the fromFnPromise option that takes a promise returned by my factory.

.fromFnPromise(Blotter.fetch())

and my factory:

app.factory('Blotter', function ($resource, $q) {
    // AngularJS will instantiate a singleton by calling "new" on this function
    var url = 'url.com?callback=JSON_CALLBACK';
    var blotterData = {};
    var ticketMaxID = 0;

    blotterData.fetch = function (isUpdate) {
      var url_params = isUpdate ?  '&diffOnly=true&lastTicketID='+ticketMaxID : '&diffOnly=false&lastTicketID=0';

      var API = $resource(
        url + url_params, {},
        {
          jsonpQuery: {
            method: 'JSONP'
          }
        }
      );
      var defObj = $q.defer();

      var blotterQuery = API.jsonpQuery();

      blotterQuery.$promise.then(function (data) {
        ticketMaxID = data.sMaxID;
        defObj.resolve(data);
      }, function (error) {
        defObj.resolve(error);
      });

      return defObj.promise;
    };


    return blotterData;

  });

I have three views in my app. When I change to different view and then come back to my view with the datatable, the table is reloading. Is there a way to keep the table untouched when changing between views?

rszczypka avatar Apr 23 '15 14:04 rszczypka

I don't think it's possible to preserve the rendered datatable (at least in my knowledge in angular and DataTables). When you switch views, your previous view's DOM is removed. So when you get back to the view, your directive will be rerendered againg.

However, you might be able to cache your server data. Maybe there is a cache function in your angular router module.

l-lin avatar Apr 23 '15 14:04 l-lin

Thanks for your reply @l-lin, at the moment I'm trying the angular way with options (http://l-lin.github.io/angular-datatables/#/angularWayWithOptions) where data comes from my service. I will update you on the results.

rszczypka avatar Apr 23 '15 14:04 rszczypka