2

I have a table with lots of columns and some rows may have undefined values so I want to show a default text instead of an empty cell depending on the column. How can I set that value?

I would expect something like this:

columnDefs: [
    {name: 'Code', field: 'code', default: 'My default value for code column'},
    {name: 'Name', field: 'name', default: 'My default value for name column'}
];

Thanks

1
  • There's an issue created, no answer yet. Commented Apr 4, 2016 at 22:52

3 Answers 3

2

Yeah you can use cellTemplate, look that, it's most easy:

columnDefs: [
  {name: 'Code', field: 'code', cellTemplate:'<div>{{row.entity.code="My default value for code column"}}</div>'},
  {name: 'Name', field: 'name', cellTemplate:'<div>{{row.entity.name="My default value for name column"}}</div>'}
];
Sign up to request clarification or add additional context in comments.

Comments

1

Use cellTemplates:

  var codeTemplate = '<div ng-if="row.entity.code">{{row.entity.code}}</div>' +
    '<div ng-if="!row.entity.code">My Default Value for code column</div>';

  var nameTemplate = '<div ng-if="row.entity.name">{{row.entity.name}}</div>' +
    '<div ng-if="!row.entity.name">My Default Value for name column</div>';

  $scope.gridOptions = {
    enableSorting: true,
    columnDefs: [{
      name: 'Code',
      field: 'code',
      cellTemplate: codeTemplate
    }, {
      name: 'Name',
      field: 'name',
      cellTemplate: nameTemplate
    }],
    data: [{
      "code": "122",
      "name": "Maximus"
    }, {
      "code": "123",
      "name": "Minimus"
    }, {
      "code": null,
      "name": "Nocodeus"
    }, {
      "code": '',
      "name": "Emptyus"
    }, {
      "code": '124',
      "name": ""
    }, {
      "code": '',
      "name": ""
    }]
  };

Example is here

1 Comment

This solution would work. However, the columns with custom "cellTemplate" having issues with filtering. It doesn't work or returns partial results
1

I achieved it through applying expression to valueFormatter

    columnDefs: [
        {name: 'Code', field: 'code', valueFormatter: 'value || My default value for code column'},
        {name: 'Name', field: 'name', valueFormatter: 'value || My default value for name column'}
    ];

I think it can also be achieved by applying expression to valueGetter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.