Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #104749
    Oleg Ilin
    Participant

    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

    #104750

    Hi,

    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 Borislavov

    Smart UI Team
    https://www.htmlelements.com/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.