October 23, 2020, 07:51:48 AM

See more Support incidents in our old archived forum.

Author Topic: Delete option using context menu  (Read 4620 times)

ssunder

  • Customers
  • Newbie
  • *
  • Posts: 25
Delete option using context menu
« on: August 06, 2014, 05:14:33 AM »
Hi Team
I have added delete option from context menu using this

// Delete option in context menu
var tableMenuItems = [
{
keyName: "DeleteItem",
name: "Delete Task",
icon: "Delete Item",
callback: function (key, opt) {
DeleteTaskRow(gantt, key, opt);
}
}
]
tableContextMenu.AddNewItems(tableMenuItems);

function DeleteTaskRow(gantt) {
//debugger;
var activity = gantt.SelectedActivity;
if (activity) {
//debugger;
gantt.RemoveActivity(activity.ID);
RebindPropertychange();
}
else
alert("Please select an item in the table first.");
}

function RebindPropertychange() {
//debugger;
var activityViews = gantt.Model.AllActivities;
for (var i = 1; i <= activityViews.length; i++) {
var view = activityViews;
//var activity = ganttControl.ActivityViews.activity;
var activity = gantt.Model.AllActivities;
var task = activity.DataSource;
//To listen the task changes.
task.PropertyChanged.subscribe(ChangeNotifier);
}
}

Now on delete click I am removing selected activity from gantt, now When I am updating that gantt and fetching all activity and updating property change notifier it is giving an error of undefined that activity is delete but gantt is not updated.

Can you suggest how can i remove that activity and can update that gantt chart with updated data and saving that in DB?

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 149
Re: Delete option using context menu
« Reply #1 on: August 06, 2014, 02:38:40 PM »
Sunder,

Can you tell us why you are calling RebindPropertyChange method from inside your DeleteTaskRow method. And what exactly are you trying to do in this method? Listen to Property Changes occurring in the data so that you can cache the updated tasks and save them into the database?

And what exactly do you mean by "..now When I am updating that gantt ...", are you talking about what is going on inside your RebindPropertyChange method? And which line exactly is giving you this error?

Also, where else are you calling your RebindPropertyChange method?


Regards,
-Raja.

ssunder

  • Customers
  • Newbie
  • *
  • Posts: 25
Re: Delete option using context menu
« Reply #2 on: August 08, 2014, 06:38:52 AM »
Raja
Thanks for update.
I am calling RebindPropertychange many places like when calling any function from context menu for add/Delete/ Making child/ Indent/ Outdent/Insert New Task Below/MoveItemDown/MoveItemUp and in callback of these calling RebindPropertychange() and in that calling ChangeNotifier(sender, args) in that calling my server side function to save data.

let me share you some code for Add Item using context Menu.
//Added Add Item in context menu
var tableContextMenu = gantt.TableContextMenu;

    // Add context menu
    var tableMenuItems = [
       {
           keyName: "AddItem",
           name: "Add Task",
           icon: "Add Item",
           callback: function (key, opt) {
               AddNewTaskRow(gantt, key, opt);
           }
       }
    ]
    tableContextMenu.AddNewItems(tableMenuItems, false);

//To add a task.
function AddNewTaskRow(gantt) {
        var newTask = getNewTask();
        addedTasks.Add(newTask.ID, newTask);
        gantt.AddNewItem(newTask);
        addnewrow = "Y";
        ShowHideGanttColumn();
        RebindPropertychange();
        adduprBlowRow = "";
        updatedTasks.Add(newTask.ID, newTask);
}

function RebindPropertychange() {
    //debugger;
    var activityViews = gantt.Model.AllActivities;
    for (var i = 1; i <= activityViews.length; i++) {
        var view = activityViews;
        //var activity = ganttControl.ActivityViews.activity;
        var activity = gantt.Model.AllActivities;
        var task = activity.DataSource;
        //To listen the task changes.
        task.PropertyChanged.subscribe(ChangeNotifier);
    }
}


function ChangeNotifier(sender, args) { 
    var timer = null;
    if (adduprBlowRow != 'y') {
        var timer;
        if (!addedTasks.Contains(sender.ID) && args.PropertyName != "SortOrder") {
            updatedTasks.Add(sender.ID, sender);
        }
        if (IndentOrOutdent == "Upper")
            updatedTasks.Add(sender.ID, sender);
        //To update the server using timer, so that it will update the server only once when the task and depended tasks changed
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(function () {

            if (controlClicked == null) {
                if (adduprBlowRow == 'Y' || parentRowId != 0) {
                    $("#progress").css("display", "block");
                    adduprBlowRow = '';
                    SaveTaskonAddrowsChange(sender, parentRowId, args);
                }
                else {
                    if (updatedTasks.length > 0) {
                        $("#progress").css("display", "block");
                        UpdateTasks();
                    }
                }
            }
            if (controlClicked != null) {
                controlClicked = null;
                updatedTasks = new RadiantQ.Gantt.Dictionary();
            }
            cacheRemovedTask(sender.ID);
            addNewRow = "";
            gantt.RedrawChartRows();
        }.bind(this), 500);
    }
}

My main aim to update that row with data and depended data in database on notifier. Is dere any disadvantage of using RebindPropertychange?

Please let me know if missing or doing some wrong code as some time it became very slow in rebind/load in gantt.

Plz provide me any best way to handle such cases like when perform any action suing context menu or gantt table edit update the same data only click once in databse.

ForumAdmin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 89
Re: Delete option using context menu
« Reply #3 on: August 08, 2014, 03:08:36 PM »
Shyam,

We will provide you a sample that illustrates the best way to implement "caching chagnes" and doing a "bulk update". Do you have a straight HTML app or a ASP.NET/MVC app?

Thanks
Support

ssunder

  • Customers
  • Newbie
  • *
  • Posts: 25
Re: Delete option using context menu
« Reply #4 on: August 11, 2014, 06:04:49 AM »
Raja
I am using ASP.NET app, it would b gr8 and also improve my application performance but make sure all things should work in that like notifier any change in start/ end / duration / desc/ percentage data should update.

Shyam

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 149
Re: Delete option using context menu
« Reply #5 on: August 11, 2014, 01:38:39 PM »
Shyam,

We have sent the sample to your email which shows the best way to cache changes and perform a bulk update.

The attachment also uses our latest JS, so make sure to copy over this JS and the CSS (remember to clear your cache as the old and new CSS file names are the same) to your project.


Regards,
-Raja.