angular-ui/ui-grid

cellTemplate function with argument

Open

#5,828 opened on Nov 22, 2016

View on GitHub
 (7 comments) (6 reactions) (0 assignees)JavaScript (2,496 forks)batch import
good first issue

Repository metrics

Stars
 (5,395 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

  • You have searched the open issues to see if this bug has been filed before. We don't want duplicate issues.
  • You have reviewed the tutorials and documentation to ensure you are using the grid correctly. ui-grid.info
  • You are using the latest version of the grid. Older versions are not patched or supported.

It would be interesting to be able to define 'cellTemplate' with a function like the example below.

Example:

//The dataItem variable is the same thing as row.entity
cellTemplate: function(dataItem: {}) {
  return '<h1>{{dataItem | json}}</h1>';
}

I would like to have this feature, because I abstracted the usage of ui-grid in my own component and I want something more generic in case we want to replace ui-grid by another grid in the future. I don't want to use 'row.entity' (neither COL_FIELD or getCellValue...) because ag-grid or kendo or any other grid have different signatures, a function returning the dataItem Object is more reusable. If some day we decide to replace ui-grid by another one (could be ui-grid v4!), and if 'row.entity' was replaced by something else, then we will be screwed. With a function(datItem) in 'cellTemplate', we will have just one place where we will need to change that: in the generic component only...

Contributor guide