Hello,
I am trying to use your grid to display some realtime data. Whenever I add data, it is rendered properly. However, when changing the data in a row, no updates are applied and the same data shows.
I saw that there is a Grid.refresh() method, but I have not seen any documentation explaining how to use it with the new React hooks paradigm. If this is the right direction, I would appreciate an example to see how to use it. If not, what is the proper way to update a grid to display realtime updates?
Thank you,
Sure, here is my grid code:
The datasource is updated in the useSocket hook, with the important parts provided here:
This is where the datasource is updated. Not shown is unrelated logic along with the gridData being returned by the hook to be used elsewhere.
I have not seen any errors when running my code. Please let me know if you need any more information.
Thanks,
Ian
|
export const Localbinding = (props) => {
const gridRef = useRef(null);
const [data, setData] = useState();
useEffect(() => {
refreshGrid();
}, [data]);
console.log('render');
function refreshGrid() {
setData(dataSource);
}
var ddObj;
const onclick = (e) => {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
grid.dataSource = [];
setData(grid.dataSource);
};
return (
<div className="control-pane">
<div className="control-section">
<button onClick={onclick}> Clear Grid</button>
<GridComponent ref={gridRef} dataSource={dataSource}>
<ColumnsDirective>
<ColumnDirective
field="id"
isPrimaryKey="true"
headerText="Order ID"
width="120"
textAlign="Right"
/>
<ColumnDirective
field="status"
headerText="Status"
width="150"
editType="dropdownedit"
/>
</ColumnsDirective>
<Inject services={[Edit, Toolbar]} />
</GridComponent>
</div>
</div>
);
};
|