I was unable to fire dataSourceChanged, later I've realised that we need to pass dataSource as {count:5, result: data} in order to make dataSourceChanged fire.
Now I'm receiving event properly but whenever grid updates (Editing/Deleting grid item, Changing pages etc) spinning wheel comes and keeps running forever.
I've used grid as common component and using it on another class components and all settings are passed as props. Let me know if I'm doing anything wrong here....
import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import '../global/static/styles.scss'
import Topbar from '../components/topbar'
import AppTable from '../components/apptable'
import * as tableData from '../data.json'
import { dashboardTableColumns } from '../components/table-configs/table-columns'
class Dashboard extends Component {
constructor(props) {
super(props)
this.state = {
partyTableData: []
}
}
grid = null
async componentDidMount() {
try {
this.setState({ partyTableData: tableData.partyTableData })
} catch (e) {
toast.error(e)
}
}
async handleDataSourceChange(dataState) {
console.log('handleDataSourceChange', dataState)
if (dataState.action === 'add') {
console.log('Added', dataState.endEdit)
} else if (dataState.action === 'edit') {
console.log('Updated', dataState.endEdit)
} else if (dataState.requestType === 'delete') {
console.log('Deleted', dataState.endEdit)
}
// above logs get's printed and I'm getting endEdit function in log as well, so endEdit must be fired below
dataState.endEdit()
}
dataStateChange(state) {
if (this.grid) {
this.grid.dataSource = { count: this.state.partyTableData.length, result: this.state.partyTableData }
}
}
render() {
return (
<>
xs={1} className="m-0">
xs={11} className="m-0 p-4">
ref={(gridRef) => this.grid = gridRef}
dataSource={{ count: this.state.partyTableData.length, result: this.state.partyTableData }}
columns={dashboardTableColumns}
gridProps={{
allowPaging: true,
allowFiltering: true,
allowGrouping: true,
pageSettings: {
pageSize: 6
},
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true
},
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
dataStateChange: this.dataStateChange.bind(this),
dataSourceChanged: this.handleDataSourceChange.bind(this),
filterSettings: {
ignoreAccent: true,
type: 'Excel'
}
}}
/>
)
}
}
export default withRouter(Dashboard)
export const dashboardTableColumns = [
{
field: 'name',
title: 'Party Name',
props: {
isPrimaryKey: true
}
},
{
field: 'mobileNo',
title: 'Mobile No.',
},
{
field: 'place',
title: 'Place',
props: {
editType: 'dropdownedit'
}
},
{
field: 'lot',
title: 'Lot',
props: {
editType: 'numericedit'
}
},
{
field: 'thaan',
title: 'Thaan',
props: {
editType: 'numericedit'
}
},
{
field: 'weight',
title: 'Weight',
props: {
editType: 'numericedit'
}
}
]
import React, { Component } from 'react'
import {
GridComponent,
ColumnDirective,
ColumnsDirective,
Page,
Filter,
Group,
Edit,
Inject,
Toolbar
} from '@syncfusion/ej2-react-grids'
import '../App.css'
class AppTable extends Component {
grid = null
constructor(props) {
super(props)
}
render() {
return (
ref={g => this.grid = g}
dataSource={this.props.dataSource || {}}
{...(this.props.gridProps || {})}
>
{
(this.props.columns || []).map((columnData, idx) => {
return (
key={`${columnData.field}_${idx}`}
field={columnData.field}
headerText={columnData.title}
{...(columnData.props || {})}
/>
)
})
}
services={[Page, Filter, Group, Edit, Toolbar]}/>
)
}
}
export default AppTable
Attachment: SyncFusion_issue_2c4de83e.rar
Thanks for the very details response, I'll surely look into this along with the reference you've provided. Will update once I get any updates.
Btw I've gone through youtube playlist on data grid. As far as I know, We surely need to rely on using custom binding for achieving this right? (CRUD operation and live filtering, Live filtering seems to work if I use filter templates) but I'm wondering what will be best way to use this along with redux.
For ex: Instead of doing live updates, I want to save all changelogs in redux store (add, edit, delete etc) so that I get to do bulk action in grid at first and then do verification later on by using changelogs derived from redux store. Is there other best practice for this in syncfusion grid system or custom binding is only way to go :)
BTW Kudos to team syncfusion, for availing community edition along with support <3 I'm focusing on syncfusion instead of react table for my next project all thanks to this.
Regards,
Yagnesh S.
Hello and again thanks for the updates.
I've already experienced and tested batch edit while watching playlist, it seems it's only good for doing some things compared to my current use case, also local binding seems more relatable to my current usecase.
For ex:
Assume I have data coming from API which I'll store in redux store as original data. Now I'll create shallow clone and store it in redux store as well which will ultimately become dataSource for my data grid (result and count pairs ofcourse).
Now let's say I'm doing 5x row insert, 2x update and 1x row deletion. I will do that update on that shallow copy of redux store resulting instant update in data grid visual as well.
But now I have changed data and original data in redux store, from which I can generate changelogs.
If I approve that changelogs only then API will be called to do that same changes in original data and if I just refreshes without confirming changelogs, It'll retain same.
• Now I'm thinking to achieve this by using dataSourceChanged event as you've mentioned but is there any other better solution to address usecases like these where we are simply doing "local binding like changes" but instead of doing it on local json, we do it on redux or etc.
Regards,
Yagnesh.
Hello Sujith!
Thanks for sharing the insights, I'm thinking to give local binding a first try since it seems first choice but if it doesn't fulfill the requirement then will go with custom bindings,
Also I'll be sharing final update here for future references once I achieve my use case. Thanks for all the information that's has been shared here.
Regards
Yagnesh!