Skip to content

Component Configuration

Tigran Gabrielyan edited this page Feb 7, 2015 · 1 revision

Component Configuration

  • autoData - automatically build response aaData array from query results (Default: true)
  • autoRender - used in conjunction with autoData, will automatically send the response (Default: true)

Setting autoRender to false will allow you to add any extra view processing that is necessary (ie. building an 'Actions' column)

  • columns - Required
Name Type Default Description
useField boolean true Whether this field is tied to a database or not (ie. Actions column would be false)
label string Humanized version of field Label for the column header
bSortable boolean true Whether the column can be sorted
bSearchable boolean true Whether the column can be searched

Special Cases


  1. Assigning a boolean to a field will mark that field as both searchable/sortable or non-searchable/non-sortable
  2. Assigning a string to a field will be used as the label
  3. Assigning null to a field will mark it as a non-table field (same as setting usedField to false)

Multiple Configs


Configurations are aliased to allow for multiple tables on a single controller. The alias name for a config will determine the primary model used for querying.

If multiple tables of the same model are needed on a single controller, use the model option to specify the model to be used for querying. See Multiple tables (same model) section in the examples below.

Examples

Basic configuration

	/**
	 * In this configuration, the alias for the configuration will 
	 * be used as the model.
	 * The `id` column will *not* be able to be sorted or searched.
	 * The `username` column will be sortable/searchable with the label `Username` (humanized version of the field).
	 * The `email` column will will be sortable/searchable with the label `Email Address`.
	 * The `Actions` column not be tied to a database field.
	 */
	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => [
					'id' => false,
					'username',
					'email' => 'Email Address',
					'Actions' => null,
				],
			],
		],
	];

More verbose configuration

	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => [
					'id' => [
						'label' => 'ID',
						'bSearchable' => false,
						'bSortable' => true,
					],
					'username',
					'email' => 'Email Address',
					'Actions' => [
						'useField' => false,
					],
				],
			],
		],
	];

Multiple tables (different models)

	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => ['id', 'username', 'email'],
			],
			'Role' => [
				'columns' => ['id', 'name', 'alias']
			],
		],
	];

Multiple tables (same model)

	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => ['id', 'username', 'email'],
			],
			'BannedUsers' => [
				'model' => 'User', // **MUST** specify the model since the alias `BannedUsers` is not a valid model
				'columns' => ['id', 'username', 'email'],
				'conditions' => ['User.banned' => true],
			],
			'Role' => [
				'columns' => ['id', 'name', 'alias']
			],
		],
	];

Using other query options

	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => ['...'],
				'contain' => ['Role'],
				'recursive' => 2,
'				'joins' => ['...'],
			],
		],
	];

Adding extra fields that are not tied to a column

	public $components = [
		'DataTable.DataTable' => [
			'User' => [
				'columns' => ['...'],
				'fields' => [ 'field1', 'field2', '...'],
			],
		],
	];