2019年7月8日 星期一

使用ag-grid 確保多人作業環境畫面永遠顯示最新資料

$scope.onTimeout = function () {
  if (!$scope.new) // 處於某種狀態暫時不更新
  {
      $http.post('...')
          .then(function (result) {
              var oldlist = Enumerable.From($scope.gridOptions.api.getModel().rowsToDisplay).Select('$.data');
              var newlist = Enumerable.From(result.data);
              var 增加資料s = [];
              newlist.ForEach(function (a) {
                  if (!oldlist.Any('$.id==' + a.id)) 增加資料s.push(a);
              });
              $scope.gridOptions.api.updateRowData({ add: 增加資料s, addIndex: 0 });
              var 減少資料s = [];
              oldlist.ForEach(function (a) {
                  if (!newlist.Any('$.id==' + a.id)) 減少資料s.push(a);
              });
              $scope.gridOptions.api.updateRowData({ remove: 減少資料s });                    Enumerable.From($scope.gridOptions.api.getModel().rowsToDisplay).ForEach(function (node) {
                  var newdata = newlist.Where('$.id==' + node.data.id).SingleOrDefault();
                  if (newdata && JSON.stringify(node.data) != JSON.stringify(newdata)) {
                    node.setData(newdata);
                    $scope.gridOptions.api.redrawRows({ rowNodes: [node] });
                  }
              });
          }).finally(function (data) {
              $timeout($scope.onTimeout, 10000);
          });
  }
  else $timeout($scope.onTimeout, 10000);
}

$timeout($scope.onTimeout, 10000);

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...