How to retrieve data from updated TreeGrid

I have populated a TreeGrid with data from SQL database and made some columns editable.  I would like to know how to get the data from the TreeGrid and use C# backend to update my database.  I have added EndEdit=endEdit and ActionComplete attributes with the corresponding JavaScript function endEdit(args) but still not working.

Can anyone assist me to get it working. I am using Version 16.1460.0.32

Thanks

3 Replies

PE Punniyamoorthi Elangovan Syncfusion Team April 20, 2018 02:08 PM UTC

Hi Michael, 
Thank you for contacting Syncfusion support.  
We have prepared the Treegrid sample with SQL database and also performed CRUD operations using actionComplete and endEdit client side events to update TreeGrid on add, edit, delete Please find the code example below:  
[Controller] 
 
public void Update(TaskData Task) 
        { 
            //Update Edited TaskDetails 
            //Using UPDATE SQL Query to Save the Modified taskData into the Table 
 
            string IDNumber = Task.TaskId; 
 
            string cmdString = "UPDATE GanttData SET TaskId=@TaskId, TaskName=@TaskName,StartDate=@StartDate,EndDate=@EndDate,Progress=@Progress,ParentId=@ParentId,Name=@Name WHERE TaskId = '" + IDNumber + "'"; 
 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SelfReferenceConnectionString"].ConnectionString);//connectionString 
 
            con.Open(); 
            using (SqlCommand sqlCommand = new SqlCommand(cmdString, con)) 
            { 
                sqlCommand.Parameters.AddWithValue("@TaskName", Task.TaskName); 
                sqlCommand.Parameters.AddWithValue("@StartDate", Task.StartDate); 
                sqlCommand.Parameters.AddWithValue("@TaskId", Task.TaskId); 
                sqlCommand.Parameters.AddWithValue("@EndDate", Task.EndDate); 
                sqlCommand.Parameters.AddWithValue("@Name", Task.Name); 
                sqlCommand.Parameters.AddWithValue("@Progress", Task.Progress);                 
                if (Task.ParentId == null) 
                { 
                    sqlCommand.Parameters.AddWithValue("@ParentId", Task.ParentId).Value = ""; 
                } 
 
                sqlCommand.ExecuteNonQuery(); 
            } 
 
            con.Close(); 
        } 
public void Add(TaskData Task) 
        { 
 
            //Here Task is the added New Task 
            //Add Task  
            //Using INSERT Query to add the New Record to SQL Table 
 
            string cmdString = "INSERT INTO GanttData ([TaskName],[TaskId],[StartDate],[EndDate],[Progress],[ParentId],[Name])" + "VALUES(@TaskName,@TaskId,@StartDate,@EndDate,@Progress,@ParentId,@Name)"; 
 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SelfReferenceConnectionString"].ConnectionString);//connectionString 
 
            con.Open(); 
            using (SqlCommand sqlCommand = new SqlCommand(cmdString, con)) 
            { 
                sqlCommand.Parameters.AddWithValue("@TaskName", Task.TaskName); 
                sqlCommand.Parameters.AddWithValue("@StartDate", Task.StartDate); 
                sqlCommand.Parameters.AddWithValue("@TaskId", Task.TaskId); 
                sqlCommand.Parameters.AddWithValue("@EndDate", Task.EndDate); 
                sqlCommand.Parameters.AddWithValue("@Progress", Task.Progress); 
                sqlCommand.Parameters.AddWithValue("@Name", Task.Name);  
                if (Task.ParentId == null) 
                { 
                    sqlCommand.Parameters.AddWithValue("@ParentId", Task.ParentId).Value = ""; 
                } 
                int test = sqlCommand.ExecuteNonQuery(); 
            } 
 
            con.Close(); 
 
        } 
 
public void Delete(TaskData Task) 
        { 
 
             //Delete Task  
            //Using Delete Query to delete Record from SQL Table 
 
             
            connectionString = string.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + Server.MapPath("App_Data") + @"\GanttDatabase2008.mdf;Integrated Security=True;Connect Timeout=30"); 
 
            string IDNumber = Task.TaskId; 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SelfReferenceConnectionString"].ConnectionString);//connectionString 
            con.Open(); 
            SqlCommand cmd = new SqlCommand("delete from GanttData where TaskId = '" + IDNumber + "'", con); 
            int result = cmd.ExecuteNonQuery(); 
            con.Close(); 
 
        } 
 
<script type="text/javascript"> 
     function endEdit(args) { 
                var editedRecord = args.data ? args.data.item : args.currentValue; 
                PageMethods.UpdateIt(editedRecord); 
            } 
 
function ActionComplete(args) { 
                var record = args.data; 
                if (args.requestType === 'addNewRow') { 
                    //Newly Added Record is obtained here , which can be updated to database 
                    addedRecord = args.addedRow; 
                   
                    PageMethods.AddIt(addedRecord); 
 
                } else if (args.requestType === 'delete') { 
                    var data = args.data; 
                    var deletedRecord = data.item; //This is the deleted item.  
                    PageMethods.DeleteIt(deletedRecord); 
                    //If deleted item has child records, we need to delete that too 
                    if (data.hasChildRecords) { 
                        deleteChildRecords(data); 
                    } 
                } 
 
            } 
function deleteChildRecords(record) { 
                var childRecords = record.childRecords, 
                    length = childRecords.length, 
                    count, currentRecord; 
                for (count = 0; count < length; count++) { 
                    currentRecord = childRecords[count]; 
                    var deletedChildRecord = currentRecord.item; //This is the deleted child item.  
                    PageMethods.DeleteIt(deletedChildRecord); 
                    //If the above deleted child record has child records, then we need to delete that too. 
                    if (currentRecord.hasChildRecords) { 
                        deleteChildRecords(currentRecord); 
                    } 
                } 
            } 
</script> 
 
We have prepared the sample with your requirement, please find the sample link below 
Please let us know if you require further assistance on this. 
Regards, 
Punniyamoorthi 
 



PR Padmini Ramamurthy Syncfusion Team April 23, 2018 04:58 AM UTC

From: Michael Ofori-Appiah
Sent: Saturday, April 21, 2018 7:26 AM
To: Syncfusion Support <[email protected]>
Subject: Re: Syncfusion support community forum 137119, How to retrieve data from updated TreeGrid, has been updated. 

Dear Support team, 
Thanks for the code.  I will have a look at it and get back to you if i encounter any problems. 
Kind regards, 
Michael 



PR Padmini Ramamurthy Syncfusion Team April 23, 2018 05:00 AM UTC

Hi Michael, 
  
Thanks for your response and we will wait to hear from you. 
  
Regards, 
Padmini R. 


Loader.
Up arrow icon