Skip to content

Commit 43ddf72

Browse files
authored
Merge pull request #143 from yajra/function-template
Add template and method to wrap scripts with a function.
2 parents 7202a2b + 6b04e49 commit 43ddf72

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Html/Builder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,16 @@ protected function makeDataScript(array $data)
274274
*/
275275
public function asOptions()
276276
{
277-
$this->setTemplate('datatables::options');
277+
return $this->setTemplate('datatables::options');
278+
}
278279

279-
return $this;
280+
/**
281+
* Wrap dataTable scripts with a function.
282+
*
283+
* @return $this
284+
*/
285+
public function asFunction()
286+
{
287+
return $this->setTemplate('datatables::function');
280288
}
281289
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
window.dtx = window.dtx || {};
2+
window.dtx["%1$s"] = function() {
3+
window.LaravelDataTables = window.LaravelDataTables || {};
4+
@if(isset($editors))
5+
@foreach($editors as $editor)
6+
var {{$editor->instance}} = window.LaravelDataTables["%1$s-{{$editor->instance}}"] = new $.fn.dataTable.Editor({!! $editor->toJson() !!});
7+
{!! $editor->scripts !!}
8+
@foreach ((array) $editor->events as $event)
9+
{{$editor->instance}}.on('{!! $event['event'] !!}', {!! $event['script'] !!});
10+
@endforeach
11+
@endforeach
12+
@endif
13+
return $("#%1$s").DataTable(%2$s);
14+
}

0 commit comments

Comments
 (0)