Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

[Changing data with the Angular way] not really work as update data in Datatables #63

@br1anchen

Description

@br1anchen

Hi,

I just start to use both datatables and this angular module (wrapper?). Thanks for the current progress of this module.
The implementation of updating data in angular way in current version v0.1.0, only works for adding data to the previous datatable copy. If the data is changed, or the element in the data array reference to different data object, it will still have the previous data array copy in the datatable.
I try to go through the source code to find solution for this case, but only fixed it in heavily hack way :(

var NGRenderer = function (options) {
        return {
          options: options,
          render: function ($scope, $elem) {
            var finishInit = false;
            var firstCallTimerFlag = false;
            ...
            parentScope.$watch(ngRepeatAttr, function (newValue,oldValue) {

              if (oTable && alreadyRendered && !_isDTOldVersion(oTable) && !finishInit) {
                oTable.ngDestroy();
              }else if(finishInit){// New Hack
                  oTable.clear().destroy();
                  alreadyRendered = true;
                  finishInit = false;
                  firstCallTimerFlag = false;
              }
              // This condition handles the case the array is empty
              if (firstCall) {
                firstCall = false;
                firstCallTimerFlag = true;// New Hack
                $timeout(function () {
                  if (!alreadyRendered) {
                    oTable = _doRenderDataTable($elem, _this.options, $scope);
                    alreadyRendered = true;
                  }
                  finishInit = true;// New Hack
                }, 1000, false);  // Hack I'm not proud of... Don't know how to do it otherwise...
              } else if(!finishInit){
                $timeout(function () {
                  oTable = _doRenderDataTable($elem, _this.options, $scope);
                  alreadyRendered = true;
                  if(!firstCallTimerFlag){ // New Hack
                      finishInit = true;
                  }
                }, 0, false);
              }
            }, true);
          }
        };
      };

Basically I instance two flags: finishInit and firstCallTimerFlag, finishInit is for skiping
oTable.ngDestroy() function to clear the data in the current datatable and reset some initial state falg to make the second time _doRenderDataTable() function still be called.
Moreover with firstCallTimerFalg, it can make after _doRenderDataTable() function, the whole update data process will not be triggered again to restore all the data from previous copy in datatable.

PS: As far as I can understand the problem here is the timing issue as the comment described. Do you have any more information about this timing issue? For example which part of the datatable rendering cause it. Please document this issue for other contributor to notice :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions