File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ It is better, you know these:
56
56
- You can use Blade Template Engine in your $content values
57
57
- The name of columns is set by returned array.
58
58
- That means, for 'posts.id' it is 'id' and also for 'owner.name as ownername' it is 'ownername'
59
+ - You can set the "index" column (http://datatables.net/reference/api/row%28%29.index%28%29 ) using set_index_column($name)
59
60
60
61
61
62
### Examples
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ class Datatables
40
40
41
41
protected $ mDataSupport ;
42
42
43
+ protected $ index_column ;
44
+
43
45
44
46
/**
45
47
* Gets query and returns instance of class
@@ -142,6 +144,17 @@ public function remove_column()
142
144
return $ this ;
143
145
}
144
146
147
+ /**
148
+ * Sets the DataTables index column (as used to set, e.g., id of the <tr> tags) to the named column
149
+ *
150
+ * @param $name
151
+ * @return $this
152
+ */
153
+ public function set_index_column ($ name ) {
154
+ $ this ->index_column = $ name ;
155
+ return $ this ;
156
+ }
157
+
145
158
/**
146
159
* Saves given query and determines its type
147
160
*
@@ -203,7 +216,14 @@ private function regulate_array()
203
216
unset($ value [$ evalue ]);
204
217
}
205
218
206
- $ this ->result_array_r [] = array_values ($ value );
219
+ $ row = array_values ($ value );
220
+ if ($ this ->index_column ) {
221
+ if (!array_key_exists ($ this ->index_column , $ value )) {
222
+ throw new \Exception ('Index column set to non-existent column " ' . $ this ->index_column . '" ' );
223
+ }
224
+ $ row ['DT_RowId ' ] = $ value [$ this ->index_column ];
225
+ }
226
+ $ this ->result_array_r [] = $ row ;
207
227
}
208
228
}
209
229
}
You can’t perform that action at this time.
0 commit comments