edit()
Edit an item using the main editing display.
Please note - this property requires the Editor extension for DataTables.
Description
This method is used to edit one or more items, optionally showing the edit form to the end user, providing them with the ability to modifying field values, or the form can be submitted programmatically without user intervention.
As of v1.5 Editor supports the ability to edit the values for one or more rows simultaneously by passing a suitable DataTable.RowSelector option in as the first parameter to this method. Furthermore, it is possible to use DataTable.ColumnSelector and DataTable.CellSelector selectors to edit all values in a column or individual cells using the object form of this option as detailed below. Finally, row, column and cell selectors can all be used simultaneously to provide complex editing options should you wish to utilise this ability in Editor.
When called, this method will set field values in the form to the record's current values automatically. If a field does not have a current value (specifically that it is not undefined), its value in the editing interface will be set to the default value as set by fields.def.
This method has two different styles of being called (see above). Editor will automatically detect which method is used and act accordingly. Although the newer style introduced in Editor 1.3 is preferred for its flexibility, the older style is still retained for backwards compatibility and can continue to be used.
Types
edit( items [, show ] [, options ] )
Show the edit entry form allowing the user to enter and modify information for the item to be edited and then subsequently submit that data.
This new form of the edit() method was introduced in Editor 1.3 to take advantage of the the updated chaining interface and form configuration options.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | items |
| No |
Item selector for the record(s) to be edited. Please note that the ability to edit multiple items was added in Editor 1.5 - earlier versions can edit a single item at a time only. The data types which can be used for this parameter depend upon which mode the Editor instance is configured in:
| |||
| 2 | show | Yes - default:true | |
Immediately show the form ( | |||
| 3 | options | Yes | |
Form configuration options, including the ability to set the title, buttons and behaviour of the form. See also | |||
Returns:
DataTable.Editor: Editor instance
edit( items [, title [, buttons [, show ]]] )
Show the edit entry form allowing the user to enter and modify information for the item to be edited and then subsequently submit that data.
This older form of the edit() method is retained in Editor 1.3 for full backwards compatibility, but the new form, documented above, is preferred.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | items |
| No |
Identical to the | |||
| 2 | title | Yes | |
Form title to display. See | |||
| 3 | buttons | Yes | |
Buttons to show in the form. See | |||
| 4 | show | Yes - default:true | |
Immediately show the form ( | |||
Returns:
DataTable.Editor: Editor instance
Examples
Edit the first row in a DataTable, setting a title and buttons:
editor
.title('Edit record')
.buttons('Update')
.edit('#example tbody tr:eq(0)');Edit the first row in a DataTable, setting a title and buttons. This achieves exactly the same as the example above, but using the form-options parameter.:
editor.edit('#example tbody tr:eq(0)', {
title: 'Edit record',
buttons: 'Update'
});Open a DataTables row for editing and submit immediately, without user interaction:
editor
.edit(row, false)
.set('name', 'Updated name')
.set('access', 'Read only')
.submit();Edit all selected rows in a DataTable:
editor.edit(table.rows({ selected: true }).indexes());Edit a DataTables' selected cells:
editor.edit({
cells: table.cells({ selected: true }).indexes()
});Edit a column in a DataTable (column index 1 in this case):
editor.edit({ columns: 1 });1.0 style API - Show the edit form for the first row in the DataTable with a submit button:
editor.edit('#example tbody tr:eq(0)', 'Edit record', 'Update');Related
The following options are directly related and may also be useful in your application development.