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

Delete Child

I am using your example for addinging deleteing and updating the chages made on the gantt.

    <script type="text/javascript">

        function ActionComplete(args) {            

            var myGantt = args.data;


            if (args.requestType === 'save' && args.addedRecord) {

                //Newly Added Record is obtained here , which can be updated to database

                var ganttRecord = args.addedRecord;

                if (args.addedRecord.parentItem)

                    ganttRecord["ParentId"] = ganttRecord.parentItem.taskId;


                PageMethods.AddIt(ganttRecord.item);

            } else if (args.requestType === 'delete') {

                var data = args.data;

                var ganttRec = data.item;

                PageMethods.DeleteIt(ganttRec);


                if (data.hasChildRecords) {

                    deleteChildRecords(data);

                }

            }

                // To update the database during Outdent,editing,indent,predecessor update operation

            else if (args.requestType === 'recordUpdate') {                

                var ganttRec = args.data.item;

                PageMethods.UpdateIt(ganttRec);

            }


        }


        //Delete inner level child records

        function deleteChildRecords(record) {

            var childRecords = record.childRecords,

                length = childRecords.length,

                count, currentRecord;

            for (count = 0; count < length; count++) {

                currentRecord = childRecords[count];

                PageMethods.DeleteRecord(currentRecord.item);

                if (currentRecord.hasChildRecords) {

                    deleteChildRecords(currentRecord);

                }

            }

        }

    </script>


which is working fine with maintasks, if I try to delete a child, the PageMethode for delete will not call the codebehind webmethod, How can this be done?

Martin

1 Reply

JD Jayakumar Duraisamy Syncfusion Team July 26, 2017 07:30 AM UTC

Hi Martin, 
We have analyzed your given code snippet and found that both server side method names are different. Can you please ensure that “DeleteRecord” method is valid method name? otherwise, rename the DeleteRecord as “DeleteIt”. 
Please refer following code snippet, 
 else if (args.requestType === 'delete') { 
                var data = args.data; 
                var ganttRec = data.item; 
                PageMethods.DeleteIt(ganttRec); 
                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]; 
                PageMethods.DeleteRecord(currentRecord.item);   // Rename it as DeleteIt 
                if (currentRecord.hasChildRecords) { 
                    deleteChildRecords(currentRecord); 
                } 
            } 
        } 
 
Please let us know, if you require any other assistance. 
Regards, 
Jayakumar D 


Loader.
Up arrow icon