-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-grid): add the ability to prevent editing by a column (#729)
- Loading branch information
1 parent
5b8de2d
commit 3c88c4c
Showing
12 changed files
with
199 additions
and
18 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
packages/dx-react-demos/src/demo-sources/grid-editing/disable-column-editing.jsxt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react';<%&additionalImports%> | ||
import { | ||
EditingState, | ||
} from '@devexpress/dx-react-grid'; | ||
import { | ||
Grid, | ||
Table, | ||
TableHeaderRow, | ||
TableEditRow, | ||
TableEditColumn, | ||
} from '@devexpress/dx-react-grid-<%&themeName%>'; | ||
|
||
import { | ||
generateRows, | ||
defaultColumnValues, | ||
} from '../../../demo-data/generator'; | ||
|
||
const getRowId = row => row.id; | ||
|
||
export default class Demo extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
columns: [ | ||
{ name: 'name', title: 'Name' }, | ||
{ name: 'sex', title: 'Sex' }, | ||
{ name: 'city', title: 'City' }, | ||
{ name: 'car', title: 'Car' }, | ||
], | ||
rows: generateRows({ | ||
columnValues: { id: ({ index }) => index, ...defaultColumnValues }, | ||
length: 8, | ||
}), | ||
editingStateColumnExtensions: [ | ||
{ columnName: 'name', editingEnabled: false }, | ||
], | ||
}; | ||
|
||
this.commitChanges = this.commitChanges.bind(this); | ||
} | ||
commitChanges({ added, changed, deleted }) { | ||
let { rows } = this.state; | ||
if (added) { | ||
const startingAddedId = (rows.length - 1) > 0 ? rows[rows.length - 1].id + 1 : 0; | ||
rows = [ | ||
...rows, | ||
...added.map((row, index) => ({ | ||
id: startingAddedId + index, | ||
...row, | ||
})), | ||
]; | ||
} | ||
if (changed) { | ||
rows = rows.map(row => (changed[row.id] ? { ...row, ...changed[row.id] } : row)); | ||
} | ||
if (deleted) { | ||
const deletedSet = new Set(deleted); | ||
rows = rows.filter(row => !deletedSet.has(row.id)); | ||
} | ||
this.setState({ rows }); | ||
} | ||
render() { | ||
const { rows, columns, editingStateColumnExtensions } = this.state; | ||
|
||
return ( | ||
<<%&wrapperTag%>> | ||
<Grid | ||
rows={rows} | ||
columns={columns} | ||
getRowId={getRowId} | ||
> | ||
<EditingState | ||
onCommitChanges={this.commitChanges} | ||
defaultEditingRowIds={[0]} | ||
columnExtensions={editingStateColumnExtensions} | ||
/> | ||
<Table /> | ||
<TableHeaderRow /> | ||
<TableEditRow /> | ||
<TableEditColumn | ||
showAddCommand | ||
showEditCommand | ||
showDeleteCommand | ||
/> | ||
</Grid> | ||
</<%&wrapperTag%>> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.