Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Make custom values available inside the javascript template #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Make custom values available inside the javascript template #301

wants to merge 1 commit into from

Conversation

rossanthony
Copy link

Need to be able to pass custom values into the javascript template, currently there is a comment in the default javascript template // custom values are available via $values array which implies this is possible, however the values are not passed through. The change in this pull request corrects this.

Basically I want to be able to conditionally trigger the dataTable (RowReordering plugin)[https://code.google.com/p/jquery-datatables-row-reordering/wiki/Index] to run, this has to be chained onto the main call to inititalise the dataTable object. For example:

<script type="text/javascript">
    jQuery(document).ready(function(){
        // dynamic table
        oTable = jQuery('#{{ $id }}').dataTable({

        @foreach ($options as $k => $o)
        {{ json_encode($k) }}: {{ json_encode($o) }},
        @endforeach

        @foreach ($callbacks as $k => $o)
        {{ json_encode($k) }}: {{ $o }},
        @endforeach

     // custom values are available via $values array

     @if(isset($values['sortable_path']))
         }).rowReordering({ sURL: "{{$values['sortable_path']}}", sRequestType: "GET" });
     @else
         });
     @endif

   });
</script>`

@rossanthony rossanthony changed the title Making custom values available inside the javascript template Make custom values available inside the javascript template Apr 28, 2015
@timgws
Copy link
Collaborator

timgws commented Apr 29, 2015

@rossanthony have you tried using $table->setOptions(array('key' => 'value'));?

@rossanthony
Copy link
Author

@timgws thanks for the reply, $table->setOptions(array('key' => 'value')) works for setting the options which are looped through in the template.

@foreach ($options as $k => $o)
        {{ json_encode($k) }}: {{ json_encode($o) }},
@endforeach

However I wanted to set a custom value to conditionally chain the rowReordering onto the dataTable object, like so:

@if(isset($values['sortable_path']))
         }).rowReordering({ sURL: "{{$values['sortable_path']}}", sRequestType: "GET" });
@else
         });
@endif

with the sortable_path being the endpoint for the server-side reordering script.

If there's a better way to achieve the same result then I'd appreciate any ideas you might have as to how else I could conditionally trigger the setup of the drag-n-drop row reordering for certain dataTables.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants