Blazor playground

Nova v3.37.0

Preview

Blazor

nv-datagrid guide

Column and cell templates, data handling and repeat templates.

← nv-datagrid

Features

  • Flexible Templating: Customize the appearance of columns and cells.
  • Action Bindings: Define actions such as edit, delete, or send email.
  • Dynamic Data Rendering: Supports array or JSON input.

Expected Behavior

Data Handling

  • Data provided to the grid will be displayed as text without modification.
  • Custom renderers can be used to format displayed data.
  • Updates to the dataset should reflect in real-time.
CaseInput DataDisplay in GridOutput on Selection
Standard Row Data{ id: 1, name: 'John' }Displays 'John' in Name col.{ id: 1, name: 'John' }

Column Display

Currently, all column data is rendered as text. Custom cell renderers can be used to achieve different visual presentations.

Repeat Template

The repeatTemplate property allows the rendering of multiple elements inside a single cell when the data is structured as an array. This is useful for displaying lists, tags, or grouped information.

Usage

To enable repeatTemplate, add it as an attribute on an nv-datagridcolumn. The grid will iterate over array elements and render them accordingly.

Example

tsx<nv-datagrid data-json='[
  {"id":1,"name":"John Doe","roles":[{"id":"1","name":"Admin"},{"id":"2","name":"User"}]},
  {"id":2,"name":"Jane Doe","roles":[{"id":"2","name":"User"}]}
]'>
  <nv-datagridcolumn accessor="name" header="Name">
    <div slot="cell">
      <strong>__name__</strong>
    </div>
  </nv-datagridcolumn>

  <nv-datagridcolumn accessor="roles" header="Role(s)" repeat-template>
    <div slot="cell">
      <nv-badge label="__roles.name__"></nv-badge>
    </div>
  </nv-datagridcolumn>
</nv-datagrid>

Behavior

  • If the roles accessor contains an array, each element will be rendered inside the same cell.
  • The repeatTemplate ensures proper iteration over array values.
  • This is especially useful for rendering multiple tags, badges, or nested items.

Notes

  • The grid does not modify original data, ensuring consistency.
  • Custom cell renderers allow advanced formatting and interactivity.

Action Binding

To enable actions within the grid, follow these steps:

  1. Add the data-bind-event attribute to interactive elements inside the grid.
  2. Use the structured format for the attribute value: actionEventToTrigger:actionNameToTrigger:propsNames.
    • Example: click:sendEmail:id,email
      • click → Event type
      • sendEmail → Action to trigger
      • id,email → Properties to pass
  3. Define an action attribute on the <nv-datagrid> component, assigning it a function that receives an ActionEvent object.

ActionEvent Object Structure

typescriptinterface ActionEvent {
  /**
   * Key action to be performed
   */
  keyAction: string;

  /**
   * Details of the action to be performed
   */
  details: any;
}

Example Usage

tsx<nv-datagrid
  data-json="[...]"
  action="handleGridAction">
  <nv-datagridcolumn accessor="actions">
    <div slot="cell">
      <nv-iconbutton size="xs" name="pencil" data-bind-event="click:edit:id"></nv-iconbutton>
      <nv-iconbutton size="xs" name="trash" data-bind-event="click:delete:id"></nv-iconbutton>
      <nv-iconbutton size="xs" name="mail" data-bind-event="click:sendEmail:id,email"></nv-iconbutton>
    </div>
  </nv-datagridcolumn>
</nv-datagrid>

Usage Examples

Using JSON Data

tsx<nv-datagrid data-json="[
        {&quot;id&quot;:1,&quot;name&quot;:&quot;John Doe&quot;,&quot;age&quot;:25,&quot;email&quot;:&quot;john.doe@mail.com&quot;, &quot;address&quot;: {&quot;city&quot;: &quot;New York&quot;, &quot;country&quot;: &quot;USA&quot;}, &quot;status&quot;: {&quot;label&quot;: &quot;success&quot;, &quot;color&quot;: &quot;1&quot;, &quot;icon&quot;: &quot;check&quot;}},
        {&quot;id&quot;:2,&quot;name&quot;:&quot;Jane Doe&quot;,&quot;age&quot;:30,&quot;email&quot;:&quot;jane.doe@mail.com&quot;, &quot;address&quot;: {&quot;city&quot;: &quot;Los Angeles&quot;, &quot;country&quot;: &quot;USA&quot;}, &quot;status&quot;: {&quot;label&quot;: &quot;warning&quot;, &quot;color&quot;: &quot;2&quot;, &quot;icon&quot;: &quot;alert-circle&quot;}}
        ]">
  <nv-datagridcolumn accessor="name" header="Name">
    <div slot="header">
      <strong>Name</strong>
    </div>
    <div slot="cell">
      <strong>__name__</strong>
    </div>
  </nv-datagridcolumn>
  
  <nv-datagridcolumn accessor="age" header="Age">
    <div slot="header">
      <em>Age</em>
    </div>
    <div slot="cell">
      <span>__age__ years old</span>
    </div>
  </nv-datagridcolumn>
  
  <nv-datagridcolumn accessor="email" header="Mail Address">
    <div slot="cell">
      <a href="mailto:__email__">__email__</a>
    </div>
  </nv-datagridcolumn>

  <nv-datagridcolumn accessor="address" header="Address">
    <div slot="cell">
      <span>__address.city__, __address.country__</span>
    </div>
  </nv-datagridcolumn>

  <nv-datagridcolumn accessor="status" header="Status">
    <div slot="header">
      <span class="text-md font-bold text-low">Status</span>
    </div>
    <div slot="cell">
      <nv-badge color="__status.color__" lead-icon="__status.icon__">
        __status.label__
      </nv-badge>
    </div>
  </nv-datagridcolumn>
  
  <nv-datagridcolumn accessor="actions">
    <div slot="cell">
      <nv-iconbutton size="xs" name="pencil" data-bind-event="click:edit:id"></nv-iconbutton>
      <nv-iconbutton size="xs" name="trash" data-bind-event="click:delete:id"></nv-iconbutton>
      <nv-iconbutton size="xs" name="mail" data-bind-event="click:sendEmail:id,email"></nv-iconbutton>
    </div>
  </nv-datagridcolumn>
</nv-datagrid>

Summary

  • The component does not alter input data unless explicitly edited.
  • Selection and editing emit corresponding events to track changes.
  • The grid offers full customization for display and behavior.