How to programmatically reload FlexGrid RestCollection data source?

Posted by: jschnurer on 24 May 2024, 2:04 pm EST

    • Post Options:
    • Link

    Posted 24 May 2024, 2:04 pm EST

    I have a custom class that inherits from RestCollectionView which I use as a FlexGrid data source in React. When the page loads, the grid successfully uses my custom CollectionView class to query my API endpoint and retrieve data & refresh its layout to show the returned items.

    Outside of this grid, in a separate modal popup, the user can create new items in the database. When the new items are created in the API, I need to tell my FlexGrid to reload its data source and refresh so that the user can see their newly created items in the grid.

    I have tried calling the refresh method of the collection view, which does nothing. I have tried calling the refresh and invalidate methods of a FlexGrid ref and they also do not reload the data source.

    I need to be able to programmatically call a method of either my flex grid instance or its data source in order for the grid to re-query my remote API using my custom CollectionView & then, after the data is returned, refresh the layout so the new items become visible.

    Please help.

  • Posted 27 May 2024, 5:40 am EST

    Hello,

    While adding the items to the DB, we assume that you are adding the items through the CollectionView instance that is bind to the FlexGrid.

    If yes, please try to use the addItem(itemtoAdd) method to add the items and refresh the data.

    And in case it does not works, please use the cv._getData() method to refresh the data with the current state sorting, filtering and paging on server.

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 28 May 2024, 10:25 am EST - Updated 28 May 2024, 10:26 am EST

    Hello,

    No, I am not adding the items to the DB using the CollectionView. I am opening a separate modal and handling a form and API calls totally separate from the grid.

    All I need to do is be able to programmatically tell the grid to reload its data from the API. Is there no way to do this?

    I am using the RestCollectionViewOdata from this example that I found:

    https://jscodemine.grapecity.com/share/BqUVvgGTT06affAC0XExrQ/

  • Posted 28 May 2024, 11:25 pm EST

    Hello,

    In this case, you need to call the RestCollectionViewOData._getData() method. That you may call with your own define function.

    Please refer to the following demo sample:

    https://jscodemine.grapecity.com/share/yv5VN4VuYkKmPKLa9iS6OA/

    This sample creates a new method named refreshOnServer and call this._getData() method. This will fetch the data from the server and view in the FlexGrid with predefined sorting, filtering and paging.

    This method should be called when your adding data from Modal is completed with success.

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 29 May 2024, 9:59 am EST

    Thanks,

    Adding a function that internally calls this._getData() was the secret solution.

    Was there somewhere in the documentation I should have found this?

  • Posted 29 May 2024, 10:41 pm EST

    Hello,

    As this is an internal method, it cannot be found in the documentation. As this method is required in your usecase so we have forwarded an enhancement request to the concerned team with the internal ID WJM-34001.

    We will let you know as we get an update on this.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels