Our blazing fast Grid component built with pure JavaScript


Post by patrickfa »

I'm running into an issue where when using a custom renderer, it keeps showing old data. We have a refresh button in the grid that fetches the new values from the database and then updates the grid. So I change a value in the backend and click that button. I can see that the custom renderer function on each column does get triggered because a console.log in that function gets triggered, and the log shows that the custom renderer does have the new values. However, even after the custom renderer gets triggered the relevant cells still show the old values. If I remove the custom renderer from the column then this problem doesn't happen, it'll show the updated values properly.

For example, here's how the columns are defined in one of our grids:

const columns = [
    {
        text: TranslationService.trans("Name"),
        field: "text",
        htmlEncode: false,
        renderer: ({ value = "", record }) => {
            return (
                <Link relative="path" to={`../categories/edit/${record.id}`}>
                    {value}
                </Link>
            );
        },
    },
    {
        text: TranslationService.trans("Icon"),
        field: "icon",
        renderer: ({ value = "" }) => {
            if (!value) {
                return null;
            }

        console.log(value);
        return <FontAwesomeIcon icon={value as IconName} size="lg" />;
    },
},
];

The console.log in the icon renderer will show the updated values, but the grid will still show the old values. If I remove the renderer entirely then the grid does show the updated values. The only way to get the custom renderers to show the new values is by reloading the entire page.


Post by marcio »

Hey Patrick,

Could you please provide a runnable case for us to debug and help you on this issue? By the configuration that you provided, it looks correct.

You can get more info about that here https://www.bryntum.com/forum/viewtopic.php?f=1&t=772

Best regards,
Márcio


Post by patrickfa »

All right, I downloaded the basic React typescript demo for grid 5.6.5 and modified it to show my issue. In the process I actually found that the problem was even more specific, because it only seems to go wrong for custom renderers that return a React element. See the attached zip.
Anyway, I made 2 columns. One returns the current timestamp directly, and the other inside a <div>. When the grid re-renders (I didn't add a refresh button, but simply updating the row height does the trick in this case) you'll see that the left column updates, while the right column remains the same.

Attachments
grid-example.zip
(1.92 MiB) Downloaded 22 times

Post by tasnim »

Hi,

When using the React component inside our renderers to react on outer state changes you'd need to use React Context/Global state manager
Please check this comment https://github.com/bryntum/support/issues/7747#issuecomment-1807557621

I've implemented React Context inside the test case you've provided and it works fine

chrome_8k4pdxTiWL.gif
chrome_8k4pdxTiWL.gif (306.14 KiB) Viewed 321 times

I've attached the updated test case below

Best regards,
Tasnim

Attachments
grid-example edited with Context Provider.zip
(1.56 MiB) Downloaded 20 times

Post Reply