This is a migrated thread and some comments may be shown as answers.

React Grid : How to invoke Refresh grid on another component change

5 Answers 1087 Views
Integration with other JS libraries
This is a migrated thread and some comments may be shown as answers.
Jiwanjyoti
Top achievements
Rank 1
Jiwanjyoti asked on 26 Dec 2017, 04:44 PM

I am trying to refresh the grid after a certain event by another component. In case of Jquery, one will do this as below.

$('#GridName').data('kendoGrid').dataSource.read();

$('#GridName').data('kendoGrid').refresh();

 

How do i achieve this in React component?

I have tried wrapping the grid in another component and i triggering state change, but in that case i get datasource.fetch is not a function.

 

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 28 Dec 2017, 06:12 AM
Hello, Jiwanjyoti,

In this scenario, the selector should be different as the Grid does not actually have an id to select it.

The following approach can be used:

$("[data-role='grid']").data('kendoGrid').dataSource.read();

If there are more Grids on the page, the jQuery find function can be used to select the Grid in a specific container.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jiwanjyoti
Top achievements
Rank 1
answered on 02 Jan 2018, 10:11 AM

Hi Stefan,

How do i achieve this in React? Why does the Grid component throws an error that datasource.fetch is not a function when state is changed? When the grid is loaded for the first time it works fine. This error comes when component is re-rendered by state change.

I am able to do the refresh on a button click using refs, but want to achieve it when state change happens.

-Jiwan

0
Jiwanjyoti
Top achievements
Rank 1
answered on 02 Jan 2018, 03:25 PM

To add more info i am using React + Redux. Below are the grid options. It works fine as long as i dont use any state. 

const gridOptions = {
            dataSource: {
                type: "odata-v4",
                transport: {
                    read: https://localhost:8704/site/vehicles/all
                    },
                schema: {
                    data: "value",
                    total: "count"
                },
                pageSize: 15,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            toolbar: ["excel","pdf"],
            excel: {
                fileName: window.resources.dbRes('AllVehicles') + ".xlsx",
                filterable: true,
                allPages: true
            },
            pdf: {
                fileName: window.resources.dbRes('AllVehicles') + ".pdf",
                filterable: false,
                allPages: true,
                avoidLinks: true,
                paperSize: "A3",
                margin: { top: "2cm", left: "1cm", right: "1cm", bottom: "1cm" },
                landscape: true,
                repeatHeaders: true,
                scale: 0.8
            },

            filterable: true,
            sortable: true,
            pageable: true,
            columnMenu: true,
            columns: columns,
            reorderable: true,
            resizable: true,
            selectable: true,
            columnHide: this.handleColumnHideEvent
        }

0
Jiwanjyoti
Top achievements
Rank 1
answered on 02 Jan 2018, 06:56 PM

Was able to figure it out. Wrapped the data source with below. 

new kendo.data.DataSource()
0
Stefan
Telerik team
answered on 03 Jan 2018, 11:10 AM
Hello, Jiwanjyoti,

I'm glad to hear that the issue is resolved.

In general, the described error can occur if the used dataSource is not actually a kendo.dataSource instance:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#kendodatadatasource

The code which I provided earlier will extract the Grid dataSource instance in React application as l:

http://dojo.telerik.com/ERAtIF

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Integration with other JS libraries
Asked by
Jiwanjyoti
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jiwanjyoti
Top achievements
Rank 1
Share this question
or