Valtimo Carbon List

Valtimo Carbon List

The valtimo-carbon-list is a component to make building lists faster and easier.

There are a few options for defining lists, besides the Simple List defined below:

Setting up a simple list

To use the CarbonListComponent there is a series of steps.

  1. Import the CarbonListModule into your module:

    sample.module.ts

    ...
    import {CarbonListModule} from '@valtimo/components'
    ...
    @NgModule({
      ...
      imports: [
        ...
        CarbonListModule,
        ...
      ]
    })
    export class SampleModule
  2. Add the valtimo-carbon-list tag in your template (this example displays a simple list):

    sample.component.html

    <valtimo-carbon-list
      [items]="items"
      [fields]="fields"
    ></valtimo-carbon-list>
  3. Define your attributes in the component code:

    sample.component.ts

    ...
    import {ColumnConfig, ViewType} from '@valtimo/components';
    ...
    
    export class SampleComponent {
     ...
     public fields: Array<ColumnConfig> = [
       {
         viewType: ViewType.TEXT,
         key: 'title',
         // this could be a translation key or just a static label
         label: 'sample.translation.title',
       },
       {
         viewType: ViewType.TEXT,
         key: 'description',
         label: 'sample.translation.description',
       },F
     ];
    
     public items: Array<any> = [
     {
         title: 'sample-title-1',
         description: 'sample-description-1',
     },
     {
         title: 'sample-title-2',
         description: 'sample-description-2',
     }
     ];
     ...
    }

This will create a simple list that shows the two items.

Clicking on rows

The (rowClicked) property is used to add an action when the user clicks on a row

The property must be added with a reference to a method

sample.component.html

<valtimo-carbon-list
    [items]="items"
    [fields]="fields"
    (rowClicked)="sampleCallback($event)"
></valtimo-carbon-list>

The method must be defined in the component

sample.component.ts

...
public sampleCallback(item: any) {
    // Code to process item
}
...

No results view

However, the no results view can be customized like this:

sample.component.html

<valtimo-carbon-list
[items]="items"
[fields]="fields"
>
  This is a custom no results view.

  This can be any template or component.
</valtimo-carbon-list>

Overview of the @Input and @Output fields of the CarbonListComponent

Inputs

Outputs

Last updated