angular-ui/ui-grid

cellDisplayGetterCache: TypeError: v1 is not a function

Open

#6.796 geöffnet am 6. Juli 2018

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (1 zugewiesene Person)JavaScript (2.496 Forks)batch import
grid-corehelp wanted

Repository-Metriken

Stars
 (5.395 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

A console error appears whenever you double click on the header row of grouped grid. The error is a bit misleading "TypeError: v1 is not a function" but after watching carefully the stack trace I found out that the error appears on the cellDisplayGetterCache function. The stack trace is the bollowing: image

Debugging the code of the ui-grid on how the cellDisplayGetterCache is set I found out the following: ` Grid.prototype.getCellDisplayValue = function getCellDisplayValue(row, col) { if ( !col.cellDisplayGetterCache ) { var custom_filter = col.cellFilter ? " | " + col.cellFilter : "";

  if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
    col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
  }
  else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
    var colField = col.field.replace(/(')|(\\)/g, "\\$&");

    col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
  }
  else {
    col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
  }
}

var rowWithCol = angular.extend({}, row, {col: col});

return col.cellDisplayGetterCache(rowWithCol);

};`

When you click on the header row it enters the first if
if (typeof(row.entity['$$' + col.uid]) !== 'undefined') { col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter); }

So for a header row with display value "2018 (1)" and custom filter "": it will be col.cellDisplayGetterCache = $parse("2018 (1)"); In Angularjs this is translated to dynamic function: ƒ (s,l,a,i){var v0,v1,v2;v1=2018;if(v1!=null){v2=1;v0=v1(v2);}else{v0=undefined;}return v0;} Because of the parenthesis the v1 is translated to v1(v2) which doesn't make sense since the v1 is assigned the value of 2018.

My workaround was to replace the if with the following: `if (typeof(row.entity['$$' + col.uid]) !== 'undefined') { var colField = col.field.replace(/(')|(\)/g, "\$&");

      col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
  }`

Steps to reproduce:

Unfortunately I couldn't reproduce in Plunker but if you try it locally it will appear for sure.

The grid should have the following features on: "ui-grid-selection ui-grid-exporter ui-grid-cellNav ui-grid-resize-columns ui-grid-move-columns ui-grid-pinning ui-grid-save-state ui-grid-auto-resize ui-grid-grouping", gridoptions: enableSorting: true, enableColumnResizing: true, enableGridMenu: true, enableRowSelection: true, enableRowHeaderSelection: true, enableSelectAll: false, enableFiltering: true, exporterMenuCsv: false, exporterMenuPdf: false, exporterSuppressColumns: [" "], and grouped by a column like this: { displayName: this.config.tmMonthFolderYearTitle, field: "TMMonthFolderYear", width: "10%", visible: true, filter: { type: this.uiGridConstants.filter.SELECT, selectOptions: [] }, grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' } },

Try to double click on the header row, at the value displayed and the above error message will appear.

Contributor Guide