public renderNextPageAndupdateCache()

in src/Explorer/Tables/DataTable/TableEntityListViewModel.ts [168:229]


  public renderNextPageAndupdateCache(sSource: any, aoData: any, fnCallback: any, oSettings: any) {
    var tablePageSize: number;
    var draw: number;
    var prefetchNeeded = true;
    var columnSortOrder: any;
    // Threshold(pages) for triggering cache prefetch.
    // If number remaining pages in cache falls below prefetchThreshold prefetch will be triggered.
    var prefetchThreshold = 10;
    var tableQuery = this.tableQuery;

    for (var index in aoData) {
      var data = aoData[index];
      if (data.name === "length") {
        tablePageSize = data.value;
      }
      if (data.name === "start") {
        this.tablePageStartIndex = data.value;
      }
      if (data.name === "draw") {
        draw = data.value;
      }
      if (data.name === "order") {
        columnSortOrder = data.value;
      }
    }
    // Try cache if valid.
    if (this.isCacheValid(tableQuery)) {
      // Check if prefetch needed.
      if (this.tablePageStartIndex + tablePageSize <= this.cache.length || this.allDownloaded) {
        prefetchNeeded = false;
        if (columnSortOrder && (!this.cache.sortOrder || !_.isEqual(this.cache.sortOrder, columnSortOrder))) {
          this.sortColumns(columnSortOrder, oSettings);
        }
        this.renderPage(fnCallback, draw, this.tablePageStartIndex, tablePageSize, oSettings);
        if (
          !this.allDownloaded &&
          this.tablePageStartIndex > 0 && // This is a case now that we can hit this as we re-construct table when we update column
          this.cache.length - this.tablePageStartIndex + tablePageSize < prefetchThreshold * tablePageSize
        ) {
          prefetchNeeded = true;
        }
      } else {
        prefetchNeeded = true;
      }
    } else {
      this.clearCache();
    }

    if (prefetchNeeded) {
      var downloadSize = tableQuery.top || this.downloadSize;
      this.prefetchAndRender(
        tableQuery,
        this.tablePageStartIndex,
        tablePageSize,
        downloadSize,
        draw,
        fnCallback,
        oSettings,
        columnSortOrder,
      );
    }
  }