Skip to content

Commit 1667925

Browse files
committed
Updated README
1 parent ed93869 commit 1667925

1 file changed

Lines changed: 7 additions & 138 deletions

File tree

README.md

Lines changed: 7 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -2,143 +2,12 @@
22
DataTable is a cakephp plugin for [JQuery DataTables](http://datatables.net/).
33

44
# Requirements
5-
* CakePHP 2.2 or higher
5+
* CakePHP >= 2.2
6+
* PHP >= 5.4
67

7-
# Installation
8-
9-
_[Manual]_
10-
11-
1. Download this: [http://github.com/tigrang/cakephp-datatable/zipball/master](http://github.com/tigrang/cakephp-datatable/zipball/master).
12-
2. Unzip
13-
3. Copy the resulting folder to `app/Plugin`
14-
4. Rename the folder to `DataTable`
15-
16-
_[GIT Submodule]_
17-
18-
In your app directory run:
19-
20-
git submodule add https://github.com/tigrang/cakephp-datatable.git Plugin/DataTable
21-
git submodule init
22-
git submodule update
23-
24-
_[GIT Clone]_
25-
26-
In your plugin directory run:
27-
28-
git clone https://github.com/tigrang/cakephp-datatable.git DataTable
29-
30-
## Enable Plugin
31-
32-
In your `app/Config/bootstrap.php`:
33-
34-
CakePlugin::loadAll();
35-
// OR
36-
CakePlugin::load('DataTable');
37-
38-
# Usage
39-
40-
#### Example controller:
41-
<?php
42-
class UsersController extends AppController {
43-
44-
/**
45-
* Components
46-
*
47-
* @var array
48-
*/
49-
public $components = array(
50-
'DataTable.DataTable' => array(
51-
'triggerAction' => array('myaction') // use if your action is not 'index'
52-
'columns' => array(
53-
'id' => false, // bSearchable and bSortable will be false
54-
'username' => 'Name', // bSearchable and bSortable will be true, with a custom label `Name`
55-
// by default, the label with be a Inflector::humanize() version of the key
56-
'email' => array(
57-
'bSearchable' => 'customSearch',// will use model callback to add search conditions
58-
),
59-
'Actions' => null, // tells DataTable that this column is not tied to a field
60-
),
61-
),
62-
);
63-
64-
By default, datatable processing is triggered if the request is an ajax one and the current action is 'index'. If this isn't the case, you can set the triggerAction setting to the action you need as a string, or an array of multiple actions for that controller that should be triggered if the request is an ajax one. You can also set trigger setting to a callback in your controller to do custom detection of when to process a request as a datatable request (it should return true/false).
65-
66-
67-
/**
68-
* Helpers
69-
*
70-
* @var array
71-
*/
72-
public $helpers = array(
73-
'DataTable.DataTable',
74-
);
75-
}
76-
77-
You may now paginate more than one model in a view. This becomes useful when displaying two or more hasMany associated models for a `view` page.
78-
List all models to paginate in `$this->DataTable->paginate` property:
79-
80-
<?php
81-
public function view() {
82-
$this->DataTable->paginate = array('User', 'Article');
83-
}
84-
85-
**Note**: These models must be directly related.
86-
87-
See docblock for complete list of component settings.
88-
89-
Once you have your component setup, you will need to add your view.
90-
91-
* First create a `View/[ModelName]/datatable` folder
92-
* Create `action_name.ctp` view inside the folder
93-
94-
The DataTableResponseView (automatically set by the component) class has a member called `dtResponse` which holds
95-
the return data for jquery datatables, including `aaData`.
96-
97-
By default, the view var `$dtResults` will hold resultant model data after searching and paginating. It can be
98-
customized with the `viewVar` setting.
99-
100-
#### Example view file:
101-
102-
<?php
103-
foreach($dtResults as $result) {
104-
$this->dtResponse['aaData'][] = array(
105-
$result['User']['id'],
106-
$result['User']['username'],
107-
$result['User']['email'],
108-
'actions',
109-
);
110-
}
111-
112-
#### Example `bSearchable` callback:
113-
114-
<?php
115-
class Users extends AppModel {
116-
public function customSearch($field, $searchTerm, $columnSearchTerm, $conditions) {
117-
if ($searchTerm) {
118-
$conditions[] = array("$field LIKE" => '%' . $searchTerm); // only do left search
119-
}
120-
if ($columnSearchTerm) {
121-
$conditions[] = array($field => $columnSearchTerm); // only do exact match
122-
}
123-
return $conditions;
124-
}
125-
}
126-
127-
# Helper Usage
128-
129-
<?php
130-
$this->DataTable->render(); // renders default model for this view
131-
$this->DataTable->render('AssociatedModel'); // renders 'AssociatedModel' table
132-
133-
If you create the `<table>` yourself, be sure to add a `data-model="Model"` attribute to the table tag. The helper is still required to parse the column settings and outputs a global javascript `dataTableSettings` available for you to use.
134-
The helper by default uses the following init script:
135-
136-
$('.dataTable').each(function() {
137-
var table = $(this);
138-
var model = table.attr('data-model');
139-
var settings = dataTableSettings[model];
140-
table.dataTable(settings);
141-
});
142-
143-
The helper relies on a js var that is set inside the `dataTableSettings` block. Add `<?php echo $this->fetch('dataTableSettings'); ?>` before your scripts block.
8+
# Documentation
9+
Documentation is available on [wiki page](https://github.com/tigrang/cakephp-datatable/wiki)
14410

11+
Update 02/05/2015
12+
* v2.0.0 released which is not backwards compatible with v1.0.0
13+
* The old master was tagged as v1.0.0

0 commit comments

Comments
 (0)