Can't bind to 'clrDgField' since it isn't a known property of 'clr-dg-cell'

2.7k views Asked by At

Just started using VMWare Clarity - cool project! I have followed the samples on adding a data grid and binding to a list of users, but I get this error:

Can't bind to 'clrDgField' since it isn't a known property of 'clr-dg-cell'. 1. If 'clr-dg-cell' is an Angular component and it has 'clrDgField' input, then verify that it is part of this module.

Html template looks like this:

<clr-datagrid>

  <clr-dg-column>First Name</clr-dg-column>
  <clr-dg-column>Last Name</clr-dg-column>
  <clr-dg-column>EMail</clr-dg-column>
  <clr-dg-column>Capture Date</clr-dg-column>

  <clr-dg-row *clrDgItems="let user of users">
    <clr-dg-cell [clrDgField]="'firstName'">{{user.firstName}}</clr-dg-cell>
    <clr-dg-cell [clrDgField]="'lastName'">{{user.lastName}}</clr-dg-cell>
    <clr-dg-cell [clrDgField]="'email'">{{user.email}}</clr-dg-cell>
    <clr-dg-cell [clrDgField]="'createdDate'">{{user.createdDate | date}}</clr-dg-cell>
  </clr-dg-row>

  <clr-dg-footer>
    {{pagination.firstItem + 1}} - {{pagination.lastItem + 1}}
    of {{pagination.totalItems}} users
    <clr-dg-pagination #pagination [clrDgPageSize]="50"></clr-dg-pagination>
  </clr-dg-footer>

</clr-datagrid>

Component looks like this:

import { Component, OnInit } from '@angular/core';
import { User } from '../types/user.type';
import { SecurityService } from '../services/security.service';

@Component({
  selector: 'app-maintain-users-component',
  templateUrl: './maintain.users.component.html'
})

export class MaintainUsersComponent implements OnInit {

  public users: User[];

  constructor(private securityService: SecurityService) {
  }

  ngOnInit(): void {
    this.users = this.securityService.getUsers();
  }
}

Feature module looks like this:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ClarityModule } from 'clarity-angular';

import { SecurityRoutingModule } from './routing/security.routing.module';

import { MaintainUsersComponent } from './components/maintain.users.component';

import { SecurityService } from './services/security.service';

@NgModule({
  imports: [CommonModule, ClarityModule, SecurityRoutingModule],

  declarations: [MaintainUsersComponent],

  providers: [SecurityService],
})

export class SecurityModule { }

Application module has this:

 imports: [
      BrowserModule,
      HttpClientModule,
      ClarityModule.forRoot(),

Not sure what else to add to get rid of this error? I thought it would have everything it needed from the clarity module? Thanks.

2

There are 2 answers

0
Jeeyun On

clrDgField should go on clr-dg-column elements rather than clr-dg-cell. You can take a look at the example code here:

https://vmware.github.io/clarity/documentation/datagrid/binding-properties

0
Soumya Kanti On

You should change like this:

<clr-datagrid>

  <clr-dg-column [clrDgField]="'firstName'">First Name</clr-dg-column>
  <clr-dg-column [clrDgField]="'lastName'">Last Name</clr-dg-column>
  <clr-dg-column [clrDgField]="'email'">EMail</clr-dg-column>
  <clr-dg-column [clrDgField]="'createdDate'">Capture Date</clr-dg-column>

  <clr-dg-row *clrDgItems="let user of users">
    <clr-dg-cell>{{user.firstName}}</clr-dg-cell>
    <clr-dg-cell>{{user.lastName}}</clr-dg-cell>
    <clr-dg-cell>{{user.email}}</clr-dg-cell>
    <clr-dg-cell>{{user.createdDate | date}}</clr-dg-cell>
  </clr-dg-row>

  <clr-dg-footer>
    {{pagination.firstItem + 1}} - {{pagination.lastItem + 1}}
    of {{pagination.totalItems}} users
    <clr-dg-pagination #pagination [clrDgPageSize]="50"></clr-dg-pagination>
  </clr-dg-footer>

</clr-datagrid>

With clrDgField, you get default sorting and filtering for free.