@@ -420,6 +420,12 @@ export class DataTableDemo extends Component {
420420 < td > pi pi-bars</ td >
421421 < td > Icon of the drag handle to reorder rows.</ td >
422422 </ tr >
423+ < tr >
424+ < td > rowEditor</ td >
425+ < td > boolean</ td >
426+ < td > false</ td >
427+ < td > Displays icons to edit row.</ td >
428+ </ tr >
423429 </ tbody >
424430 </ table >
425431 </ div >
@@ -1064,7 +1070,7 @@ export class DataTableSelectionDemo extends Component {
10641070` }
10651071</ CodeHighlight >
10661072
1067- < h3 > Incell Editing</ h3 >
1073+ < h3 > Cell Editing</ h3 >
10681074 < p > Incell editing feature provides a way to quickly edit data inside the table. A cell editor is defined using the < i > editor</ i > property
10691075 that refers to a function to return an input element for the editing.</ p >
10701076
@@ -1142,6 +1148,87 @@ requiredValidator(props) {
11421148 let value = props.rowData[props.field];
11431149 return value && value.length > 0;
11441150}
1151+ ` }
1152+ </ CodeHighlight >
1153+
1154+ < h3 > Row Editing</ h3 >
1155+ < p > Row editing toggles the visibility of the all editors in the row at once and provides additional options to save and cancel editing.</ p >
1156+
1157+ < CodeHighlight className = "language-jsx" >
1158+ { `
1159+ <DataTable value={this.state.cars} editMode="row">
1160+ <Column field="vin" header="Vin" />
1161+ <Column field="brand" header="Brand" editor={this.brandEditor} onRowEditorValidator={this.onRowEditorValidator}/>
1162+ <Column field="saleDate" header="Sale Date" editor={this.saleDateEditor} >
1163+ <Column rowEditor={true} />
1164+ </DataTable>
1165+
1166+ ` }
1167+ </ CodeHighlight >
1168+
1169+ < CodeHighlight className = "language-javascript" >
1170+ { `
1171+ onEditorValueChange(props, value) {
1172+ let updatedCars = [...this.state.cars];
1173+ updatedCars[props.rowIndex][props.field] = value;
1174+ this.setState({cars: updatedCars});
1175+ }
1176+
1177+ brandEditor(props) {
1178+ let brands = [
1179+ {label: 'Audi', value: 'Audi'},
1180+ {label: 'BMW', value: 'BMW'},
1181+ {label: 'Fiat', value: 'Fiat'},
1182+ {label: 'Ford', value: 'Ford'},
1183+ {label: 'Honda', value: 'Honda'},
1184+ {label: 'Jaguar', value: 'Jaguar'},
1185+ {label: 'Mercedes', value: 'Mercedes'},
1186+ {label: 'Renault', value: 'Renault'},
1187+ {label: 'VW', value: 'VW'},
1188+ {label: 'Volvo', value: 'Volvo'}
1189+ ];
1190+
1191+ return (
1192+ <Dropdown value={this.state.cars[props.rowIndex].brand} options={brands}
1193+ onChange={(e) => this.onEditorValueChange(props, e.value)} style={{width:'100%'}} placeholder="Select a City"/>
1194+ );
1195+ }
1196+
1197+ saleDateEditor(props) {
1198+ return (
1199+ <Calendar value={this.state.cars[props.rowIndex].saleDate}
1200+ onChange={(e) => this.onEditorValueChange(props, e.value)} style={{width:'100%'}} />
1201+ );
1202+ }
1203+
1204+ onRowEditorValidator(rowData) {
1205+ let value = rowData['brand'];
1206+ return value.length > 0;
1207+ }
1208+
1209+ onRowEditInit(event) {
1210+ this.clonedCars[event.data.vin] = {...event.data};
1211+ }
1212+
1213+ onRowEditSave(event) {
1214+ if (this.onRowEditorValidator(event.data)) {
1215+ delete this.clonedCars[event.data.vin];
1216+ // Success message
1217+ }
1218+ else {
1219+ // Error message
1220+ }
1221+ }
1222+
1223+ onRowEditCancel(event) {
1224+ let cars = [...this.state.cars];
1225+ cars[event.index] = this.clonedCars[event.data.vin];
1226+ delete this.clonedCars[event.data.vin];
1227+ this.setState({
1228+ cars
1229+ })
1230+ }
1231+
11451232` }
11461233</ CodeHighlight >
11471234
@@ -2055,6 +2142,12 @@ export class DataTableStateDemo extends Component {
20552142 < td > session</ td >
20562143 < td > Defines where a stateful table keeps its state, < br /> valid values are "session" for sessionStorage and "local" for localStorage.</ td >
20572144 </ tr >
2145+ < tr >
2146+ < td > editMode</ td >
2147+ < td > string</ td >
2148+ < td > cell</ td >
2149+ < td > Defines editing mode, options are "cell" and "row".</ td >
2150+ </ tr >
20582151 </ tbody >
20592152 </ table >
20602153 </ div >
@@ -2187,6 +2280,30 @@ export class DataTableStateDemo extends Component {
21872280 < td > value: Value displayed by the table.</ td >
21882281 < td > Callback to invoke after filtering and sorting to pass the rendered value.</ td >
21892282 </ tr >
2283+ < tr >
2284+ < td > rowEditorValidator</ td >
2285+ < td > data: Editing row data</ td >
2286+ < td > Callback to invoke to validate the editing row when the save icon is clicked on row editing mode.</ td >
2287+ </ tr >
2288+ < tr >
2289+ < td > onRowEditInit</ td >
2290+ < td > event.originalEvent: Browser event < br />
2291+ event.data: Editing row data </ td >
2292+ < td > Callback to invoke when the editing icon is clicked on row editing mode.</ td >
2293+ </ tr >
2294+ < tr >
2295+ < td > onRowEditSave</ td >
2296+ < td > event.originalEvent: Browser event < br />
2297+ event.data: Editing row data</ td >
2298+ < td > Callback to invoke when the save icon is clicked on row editing mode.</ td >
2299+ </ tr >
2300+ < tr >
2301+ < td > onRowEditCancel</ td >
2302+ < td > event.originalEvent: Browser event < br />
2303+ event.data: Editing row data < br />
2304+ event.index: Editing row data index</ td >
2305+ < td > Callback to invoke when the cancel icon is clicked on row editing mode.</ td >
2306+ </ tr >
21902307 </ tbody >
21912308 </ table >
21922309 </ div >
0 commit comments