i m trying to build a gantt chart using Dhtmlx library in my project so i try to pass the id of the project in the gantt.load function to show just the gantt of that project .but and it show me these error "Invalid argument for gantt.parse or gantt.load. An object or a JSON string of format https://docs.dhtmlx.com/gantt/desktop__supported_data_formats.html#json is expected. Actual argument value: "failed " " any help guys??? this is my Gantt.vue:
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<div id="gantt_here">
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
key: this.$route.params.id,
}
},
created(){
gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
gantt.config.order_branch = true;/*!*/
gantt.config.order_branch_free = true;/*!*/
gantt.init("gantt_here");
gantt.load("/api/data/"+this.key);
var dp = new gantt.dataProcessor("/api");/*!*/
dp.init(gantt);/*!*/
dp.setTransactionMode("REST");/*!*/
},
mounted() {
console.log('Component mounted.')
}
}
and this is my GanttController:
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Task;
use App\Link;
class GanttController extends Controller
{
public function get($id){
$tasks= new Task;
if($tasks->projet_id== $id){
$tasks = new Task();
$links = new Link();
return response()->json([
"data" => $tasks->orderBy('sortorder')->get(),
"links" => $links->all()
]);
}
else{
return response()->json([
"failed"
]);
}
}
}
and this is my route in api.php:Route::get('/data/{id}', 'API\GanttController@get');
Gantt expects the data in the JSON format. But the gantt.load()
method doesn't separately send the arguments to the server-side. You can try using the custom routing, but you need to manually implement a function to send the data to the server-side, then you can add it in the "create"
, "update"
and "delete"
actions:
https://docs.dhtmlx.com/gantt/desktop__server_side.html#customrouting
Or you can try obtaining the ID in the controller, for example:
public function get($id){
// $id: "/api/data/34"
$id = substr($id, 10); // $id: "34"
$tasks= new Task;
if($tasks->projet_id== $id){ // $id: "34"