JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Data Grid › On RwClass
- This topic has 1 reply, 2 voices, and was last updated 1 year, 7 months ago by svetoslav_borislavov.
-
AuthorPosts
-
April 24, 2023 at 10:36 pm #104749Oleg IlinParticipant
Dear friends,
Where and how can I use the function
onRowClass(index, data, row)?
Can I access it programmatically?
Does it apply dynamically to rows?Best Regards
OI
April 25, 2023 at 3:54 am #104750svetoslav_borislavovParticipantHi,
The onRowClass can be used as callback property of the Grid. Using the
onRowClass
function you can dynamically apply a CSS class(es) to an entire row.onRowClass
should return a CSS class name string or an array of CSS class names divided by space.You can set the callback initially:
window.Smart(‘#grid’, class {
get properties() {
return {
behavior: { columnResizeMode: ‘growAndShrink’ },
dataSource: new Smart.DataAdapter({
dataSource: window.generateData(1000),
dataFields: [
‘id: number’,
‘firstName: string’,
‘lastName: string’,
‘productName: string’,
‘quantity: number’,
‘price: number’,
‘total: number’
]
}),
onRowClass(index, data, row) {
if (index % 2 === 0) {
return ‘row-class-1’
}
if (data.firstName === ‘Andrew’) {
return ‘row-class-2’;
}
},
columns: [
{ label: ‘First Name’, dataField: ‘firstName’ },
{ label: ‘Last Name’, dataField: ‘lastName’ },
{ label: ‘Product’, dataField: ‘productName’ },
{ label: ‘Quantity’, dataField: ‘quantity’ },
{ label: ‘Unit Price’, dataField: ‘price’ },
{ label: ‘Total’, dataField: ‘total’ }
]
}
}
});If you want to set it dynamically, you can do so:
const grid = document.querySelector(‘#grid’)grid.onRowClass = (index, data, row) => {
if (index % 2 === 0) {
return ‘row-class-1’
}
if (data.firstName === ‘Andrew’) {
return ‘row-class-2’;
}
}We have a topic for different ways of styling Grid rows, you can find it here:
https://www.htmlelements.com/docs/grid-styling-rows/Best Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/ -
AuthorPosts
- You must be logged in to reply to this topic.