Deamon
Deamon

Reputation: 109

ui-grid: How to use function for columnDefs

For some reason I need to create headers dynamically because of component I used.

So I have a function which and that function I want to use to provide values to columnDefs

ctrl.getColumnDefs = () => {
    let columns = []
    if (name === 'deamon') {
        var normalCol = {
          field: 'name',
          enableSorting: true,
          cellTooltip: (row, col) => row.entity[col.field],
          enableCellEdit: false
        };

    return columns.push(normalCol);
}

Then I am using

ctrl.grid = {
 columnDefs: getColumnDefs() 
}

Which is throwing TypeError: self.options.columnDefs.forEach is not a function

Upvotes: 0

Views: 574

Answers (1)

Radu Diță
Radu Diță

Reputation: 14201

You are returning the value of push. That returns the new length of the array as per docs here.

You probably want to return columns instead of push.

Probably you want this

columns.push(normalCol)
return columns

Upvotes: 1

Related Questions