We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

CRUD operations example with PHP

I have a small issue, I cannot find an example for EDIT,CREATE,DELETE for gantt in EJ2 using php, and I got stuck on using $batch, managed to process the request but ended up with the chart continuously loading after getting 200 from the api

3 Replies

PP Pooja Priya Krishna Moorthy Syncfusion Team October 29, 2019 12:19 PM UTC

Hi Razvan, 
Greetings from Syncfusion support. 
 
We have prepared a Gantt CRUD sample using PHP version 7.1.30, fetching data from the server using dataManager. 
 
Replace the port number highlighted in the below code snippet based on your SQL port, 
 
  function update(){   
        $conn = new mysqli("localhost", "root","", "gantt", 3306);   
        //... 
  } 
 
  function add() { 
        $conn = new mysqli("localhost", "root", "", "gantt", 3306); 
        //... 
    } 
  function delete () 
    { 
        $conn = new mysqli("localhost", "root", "", "gantt", 3306); 
        //... 
    } 
 
To perform CRUD operations by using actionComplete client-side event, identify the operation by  action event argument as add, DialogEditing/ CellEditing and delete for add, edit and delete actions respectively. 
 
Please find the below code example. 
 
var gantt = new ej.gantt.Gantt({ 
   dataSource: new ej.data.DataManager({ 
       url: 'http://localhost:7777/GanttEJ2/getData.php/?action=getData', 
       crossDomain: true 
   }).executeQuery(new ej.data.Query()).then(function (e) { 
       gantt.dataSource = e.result; 
   }), 
   //... 
   actionComplete: function (args) { 
       if (args.action == "add" && args.newTaskData) { 
           var data = JSON.stringify(args.newTaskData); 
           $.ajax({ 
              type: "POST", 
              url: 'http://localhost:7777/GanttEJ2/getData.php/?action=add', 
              data: data, 
              success: function (data) { 
                 console.log(data); 
              } 
           }); 
       } 
 
       if (args.action == "DialogEditing" || args.action == "CellEditing") { 
           var data = JSON.stringify(args.data.taskData); 
           $.ajax({ 
               type: "POST", 
               url: 'http://localhost:7777/GanttEJ2/getData.php/?action=update', 
               data: data, 
                  //... 
            }); 
        } 
        if (args.action == "delete") { 
            var data = JSON.stringify(args.data[0].taskData); 
            $.ajax({ 
               type: "POST", 
               url: 'http://localhost:7777/GanttEJ2/getData.php/?action=delete', 
               data: data, 
               //... 
            }); 
        } 
     } 
}); 
 
Please get back to us if you require further assistance on this. 
 
Regards, 
Pooja Priya K. 
 



RN Razvan Nicolae November 1, 2019 09:23 AM UTC

Hello Pooja,
The sample you provided me works almost perfectly, I found a flaw in it.
If I try to use the columns attribute it throws an error if I try to edit(I need to add some specific columns like Status and Trackers)
columns: [
{
field: 'TaskName',
headerText: 'Task Name',
// allowEditing: false
},
],
Here is the error: 
 Thank you,
Razvan




SD Saranya Dhayalan Syncfusion Team November 4, 2019 12:37 PM UTC

Hi Razvan, 
  
We have prepared a sample by using columns attribute. We also included custom column (Status) and performed edit action. We are not able to reproduce the error. Please find the demo sample from below link. 
 
 
Could you please check the above sample and if still issue persist please modify our provided sample to reproduce the issue, so that it will be very helpful to provide you a solution. 
  
Regards, 
Saranya D 


Loader.
Live Chat Icon For mobile
Up arrow icon