This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

deroccha
deroccha

Did anybody used already in a custom Plugin Chumpers Datatable. How do I let to render data in components template?

that0n3guy
that0n3guy

I used it in the october backend on a small project. It was a table that loaded below a backed form so not a component, but same idea.

Since your questions isn't very specific, here is how I did it:

Created an extra datatable class in myplugin/directory/class/Ocaform.php, looked something like:

<?php namespace OCA\Webforms\Classes;

use Illuminate\Support\Facades\Input;
use MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass;
use OCA\Webforms\Models\Formposts;
use OCA\Webforms\Models\Ocaform as OcaformsModel;

class Ocaforms extends \Controller
{

    private $rules = [
      //'ocaform_id' => 'required',
    ];

    private $ocaform;

    private $post;
    public function getDatatable($ocaform_id)
    {
        $helpers = new Helpers();
        $header = $helpers->getLastpostHeader($ocaform_id);

        return \Datatable::collection(Formposts::where('ocaform_id', intval($ocaform_id))->orderBy('created_at', 'desc')->get($header))
            ->showColumns($header)
            ->make();
    }
}

You can see I just extended the regular larvel controller Ocaforms extends \Controller.

In my backend template (happend to be the update template) I had:

<div class="row">
    <div class="col-md-4">
        <h2>Tokens for Redirect URL & Emails</h2>
        <?= Datatable::table()
        ->addColumn('token','example data')       // these are the column headings to be shown
        ->setData($tokens)
        ->noScript()
        ->render();  ?>
    </div>
    <div class="col-md-8">
        <h2>Previously Submitted Forms. <small>Columns based on the fields in the last submitted form</small></h2>
        <?= Datatable::table()
        ->addColumn($theader)       // these are the column headings to be shown
        ->setOptions('order', array([$ordercolumn ,"desc"]))
        ->setUrl(route('that0n3guy.api.formposts', $ocaform_id))   // this is the route where data will be retrieved
        ->render() ?>
    </div>
</div>

In my routes.php I had:

Route::get('backend/that0n3guy/api/formposts/{id}', array('as'=>'that0n3guy.api.formposts', 'uses'=>'OCA\Webforms\Classes\Ocaforms@getDatatable'));

That should get you started pretty well...

deroccha
deroccha

thanks a lot!!

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.