create()

Since: Editor 1.0

Create a new item.
Please note - this property requires the Editor extension for DataTables.

Description

This method is used to create new records, optionally showing the create form to the end user for them to input information, or the form can be submitted programmatically without user intervention.

Field values in the form are automatically set to their default values as configured by fields.def.

As of Editor 1.5 this method can be used to create multi-rows from a single form due to the multi-row editing ability. When using multi-row editing field values can be addressed individually through the row id - however, when creating new rows the rows do not have ids assigned until submitted to the server, so the rows are assigned indexes 0...N where N is the number of rows being created.

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

create( [ count, ] [ show, ] [ options ] )

Since: 1.3

Set up the Editor instance to create one or more new rows. The information to be submitted for the new rows can be entered by the end user through the Editor interface, or via the API for programmatic row creation.

This new form of the create() method was introduced in Editor 1.3 to take advantage of the the updated chaining interface and form configuration options.

Parameters:

Returns:

DataTable.Editor: Editor instance

create( [ title [, buttons [, show ]]] )

Since: 1.0

Show the create new entry form allowing the user to enter information for a new row and then subsequently submit that data.

This older form of the create() method is retained in Editor 1.3 for full backwards compatibility, but the new form, documented above, is preferred.

Parameters:

Returns:

DataTable.Editor: Editor instance

Examples

Show the create form with a submit button - using API chaining:

editor
	.title('Add new record')
	.buttons('Save')
	.create();

Show the create form with a submit button - using form-options to configure the title and buttons. This is exactly the same end effect as the above example, just a different way of doing it!:

editor.create({
	title: 'Add new record',
	buttons: 'Save'
});

Don't show the form and automatically submit it after programmatically setting the values of fields (and using the field defaults):

editor
	.create(false)
	.set('name', 'Test user')
	.set('access', 'Read only')
	.submit();

Create three new rows and set a first-name parameter to different values for each:

editor.create(3, 'Add new record', 'Save');
editor
	.field('first-name')
	.multiSet(0, 'Allan')
	.multiSet(1, 'Bob')
	.multiSet(2, 'Charlie');

Show create form using the 1.0 style API.:

editor.create('Add new record', 'Save');

Related

The following options are directly related and may also be useful in your application development.