# RadzenDataGrid (component) custom attributes

**URL:** <https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648>\
**Category:** Radzen.Blazor Components\
**Created:** [November 8, 2023, 7:58am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648 "2023-11-08T07:58:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanz](https://forum.radzen.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@stefanz](https://forum.radzen.com/u/stefanz)\
**Post date:** [November 8, 2023, 7:58am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/1 "2023-11-08T07:58:57Z")

</div>

Hi,

We would like RadzenDataGrid (and other Razden Components) to generate a custom attribute e.g. `data-testid="my-grid"` for UI test automation navigation. Is this possible?

I can see that RazdenComponent exposes Attributes [Components (Blazor) (radzen.com)](https://www.radzen.com/documentation/blazor/components/#attributes) however there is no example on how to use this (with binding e.g.) and I could not get it to work with experimenting...

Kind regards,  
Stefan

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 8, 2023, 8:03am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/2 "2023-11-08T08:03:27Z")

</div>

Hi @stefanz,

You just need to assign the custom attribute:

```auto
<RadzenDataGrid data-testid="mygrid" ...>

```

---

<div class="post-metadata">

**Author:** ![stefanz](https://forum.radzen.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@stefanz](https://forum.radzen.com/u/stefanz)\
**Post date:** [November 8, 2023, 8:32am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/3 "2023-11-08T08:32:30Z")

</div>

> [@korchev](#):
>
> `data-testid="mygrid"`

Thank you that works, user error obviously...

---

<div class="post-metadata">

**Author:** ![stefanz](https://forum.radzen.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@stefanz](https://forum.radzen.com/u/stefanz)\
**Post date:** [November 9, 2023, 9:52am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/4 "2023-11-09T09:52:01Z")

</div>

@korchev is there a supported way to do this programmatically (outside of this component/blazor markup?)

we would like to conditionally set the data-testid and preferably avoid introducing if...else into (every) razor markup

Something like this  
` public static void SetDataTestId(this RadzenComponent component, string dataTestId) { if (..running tests...) { var attributes = new Dictionary<string, object>(component.Attributes); attributes["data-testid"] = dataTestId; #pragma warning disable BL0005 // Component parameter should not be set outside of its component. component.Attributes = attributes; #pragma warning restore BL0005 // Component parameter should not be set outside of its component. } }`

I appreciate this might be a Blazor limitation not Razden, still worth asking

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [November 9, 2023, 9:57am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/5 "2023-11-09T09:57:00Z")

</div>

I think setting an attribute to null makes it not render. You try that instead. I don't think setting attributes per component instance should be done (as you are trying with the extension method).

Another solution is to inherit from RadzenDataGrid and use component activator for tests. Check this thread for more info: [Localize Radzen Datagrid Advanced Filter - #5 by korchev](http://forum.radzen.com/t/localize-radzen-datagrid-advanced-filter/11164/5)

---

<div class="post-metadata">

**Author:** ![stefanz](https://forum.radzen.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@stefanz](https://forum.radzen.com/u/stefanz)\
**Post date:** [November 9, 2023, 10:15am UTC](https://forum.radzen.com/t/radzendatagrid-component-custom-attributes/15648/6 "2023-11-09T10:15:29Z")

</div>

null works thank you
