Our blazing fast Grid component built with pure JavaScript


Post by jintech »

getRowFor does not seem to work either. I will be updating the version soon but for the time being, I want to implement this functionality. Updating the version would also require a lot of testing as there are other areas where the bryntum grid library is being used and I don't want them to break. For the time being I want to temporarily implement the functionality with a suitable alternative and then make changes later when the the library is updated.

Can you provide an example of how to use getRowFor inside the onItem event function?
My current version of the bryntum grid is 5.2.7


Post by marcio »

Hey jintech,

Checking the API diff tool, I checked that getRecordFromElement is available on 5.2.7, as it was added earlier. How are you trying to use that function?

https://bryntum.com/products/grid/docs/api/apidiff

Attachments
Screenshot 2024-01-22 at 14.12.44.png
Screenshot 2024-01-22 at 14.12.44.png (131.14 KiB) Viewed 414 times

Best regards,
Márcio


Post by jintech »

Not sure TBH. I checked the source param in the beforeShowMenu param in my environment and the owner object inside it did not have the getRecordFromElement in there.
Also important thing to note is that in beforeShowMenu function, the source.owner is a Grid object so it has the getRecordFromElement and getRowFor functions inside it. However for onItem event, the source.owner is a Menu item and does not contain any of these functions so we cannot use that. This was tested on the latest code as well in the bryntum grid demos


Post by marcio »

Oh, You meant inside onItem, sorry, I thought you were talking about the previous snippet, my mistake!

You can use https://bryntum.com/products/grid/docs/api/Core/widget/Widget#function-query-static

Widget.query('grid')

Just put your Grid selector there, and you'll have the Grid instance with the functions that you need.

Best regards,
Márcio


Post by jintech »

The above-provided code fetches the Grid object containing the required functions. However, the getRecordFromElement returns null

onItem({source, item}) {
        var gridObj = Widget.query('grid');
        const rec = gridObj.getRecordFromElement(source.element);
        console.log(rec);		
}

Post by alex.l »

Demo code was written for Menu context, not for menu Item context. Please try owner's element.

source.owner.element

All the best,
Alex


Post by jintech »

Its still returning null

onItem({source, item}) {
        var gridObj = Widget.query('grid');
        const rec = gridObj.getRecordFromElement(source.owner.element);
        console.log(rec);		
}
obj.png
obj.png (227.24 KiB) Viewed 348 times
parent_el.png
parent_el.png (49.02 KiB) Viewed 344 times

Post by tasnim »

Hi,

Please try using https://developer.mozilla.org/en-US/docs/Web/API/Element/closest on the button element

    onItem({source, item}) {
        var gridObj = source.up('grid');
        const element = source.parent.owner.element.closest('.b-grid-row');
        const rec = gridObj.getRecordFromElement(element);
        console.log(rec);		
    }

It works fine here.


Post by jintech »

Thanks a lot. Its working as per my requirement


Post Reply