Kentico CMS 7.0 Developer's Guide

Creating custom tables

Creating custom tables

Previous topic Next topic Mail us feedback on this topic!  

Creating custom tables

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

You can find the custom tables module at two locations of Kentico interface:

 

Site Manager -> Development -> Custom tables allows you to create new custom tables, given you are the site's global administrator. You can also view and manipulate data in existing tables using this interface.

CMS Desk -> Tools -> Custom tables allows you to view and manipulate data in existing custom tables only.

 

Note that you can create new custom tables using the wizard only. There is currently no simple way of creating custom tables using the API. This is due to the need to create related objects and settings—these tasks are handled by the wizard.

 

Creating a table using the New custom table wizard

 

In the following example, you will create a new custom table using the New custom table wizard.

 

Starting the New custom table wizard

 

1. Navigate to Site Manager -> Development -> Custom tables.

 

2. Click New custom table (AddCustomTable). The New custom table wizard starts.

 

Step 1

 

1. Enter the following details:

 

Custom table display name: People

odisplay name is used in Kentico CMS user interface.

Custom table code name: customtable.People

odisplay name is used in website code — always preceded by a namespace, which allows you to have different tables of the same name in different contexts.

 

devguide_clip0520

 

2. Click Next to continue.

 

Step 2

 

In this step, you are given a choice from the two following options:

 

Create a new database table - choose this option to create a brand new table in the system's database.

Database table name - the actual name of the table in the system database. A name in the <namespace>_<code name> format is pre-filled automatically.

Primary key name - primary key column name, pre-filled with the ItemID value.

 

Use an existing database table - choose this option if you already have a physical table in the system database and want to register it in the system.

Database table name - the actual name of the table in the system database. The drop-down list offers only database tables which are not part of the default Kentico CMS database schema and are not yet registered for any object.

Primary key name - primary key column name. The original table's primary key column is used automatically.

 

The following check-boxes allow you to choose the default fields that you want to include in the custom table:

 

Include ItemGUID field - globally unique ID of the particular custom table data record.

Include ItemCreatedBy field - user name of the user who created the item.

Include ItemCreatedWhen field - date and time of when the item was created.

Include ItemModifiedBy field - user name of the user who last modified the item.

Include ItemModifiedWhen field - date and time of last modification.

Include ItemOrder field - order of the item when table content list is displayed. The lower number, the earlier position in the list.

 

1. Choose Create a new database table.

 

2. Leave the value customtable_People in the Database table name field.

 

3. Make sure all the check-boxes are turned on.

 

devguide_clip0521

 

4. Click Next to continue.

 

Step 3

 

Third step contains the field editor. The field editor lets you define which columns will be included in the database table.

 

1. Create a field using the New attribute (AddWebPart) button with the following properties:

 

Column name: FirstName

Attribute type: Text

Attribute size: 100

Field caption: First name

Form control: Text box

 

2. Click the Save Save button.

 

3. Create a second field using the New attribute (AddWebPart) button with the following properties:

 

Column name: LastName

Attribute type: Text

Attribute size: 100

Field caption: Last name

Form control: Text box

 

4. Click the Save Save button.

 

5. Create a third field using the New attribute (AddWebPart) button with the following properties:

 

Column name: DateOfBirth

Attribute type: Date and time

Field caption: Date of birth

Form control: Calendar

Editing control settings -> Edit time: unchecked

 

6. Click the Save Save button.

 

devguide_clip0522

 

7. Once you are finished, click the Next button.

 

Step 4

 

Select on which sites the custom table will be available.

 

1. Click Add sites. A dialog box opens.

 

2. Choose Corporate Site (or any site that you want to add the custom table to) in the pop-up dialog.

 

devguide_clip0523

 

3. Click Next to proceed to the following step.

 

Step 5

 

Configure the indexing of data in the custom table by the Smart Search module. The four drop-down lists at the top determine which fields of the table will be displayed in search results.

 

1. Change the values to the following:

 

Title field: LastName

Content field: FirstName

Image field: none

Date field: ItemModifiedWhen

 

devguide_clip0956

 

2. Leave the rest of the settings at default values and click Next.

 

For more information on settings in this step, please refer to Modules -> Smart search -> Object settings.

 

Step 6

 

The last step gives you an overview of the tasks executed by the wizard.

 

devguide_clip0524

 

End the wizard by clicking Finish. You will be redirected back to the list of custom tables in Site Manager -> Development -> Custom tables.