Hi, the best way to apply a custom style on a widget is through the SCSS files in the Styling section of your app/module.
This is certainly true for widgets who add more then 1 layer of HTML markup (like the datagrid widget).
You cannot add classes on each level of the HTML markup, so you need to refer to it through css.
You can read more on that here: https://docs.mendix.com/howto/front-end/customize-styling-new/