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.
Unfortunately, activation email could not send to your email. Please try again.

Problem adding new record as a son

Thread ID:

Created:

Updated:

Platform:

Replies:

119177 May 18,2015 03:22 PM May 25,2015 09:27 AM ASP.NET MVC 6
loading
Tags: Gantt
Otto Moura Machado Filho
Asked On May 18, 2015 03:22 PM

I'm having problems adding new records.

Before the last update I have used this code on ActionComplete:

if (args.requestType === 'save' && args._cAddedRecord) {
            var ganttRecord = args.data;

            if (args._cAddedRecord.parentItem)
                ganttRecord["ParentId"] = args._cAddedRecord.parentItem.item.idatividade;

and then post args._cAddedRecord.item to server, and it used to work.

Then i removed the above code and It works. With the last update adding "sons" to a record is not working. Gantt is adding the new record as a "sibling" of the selected record.

How can I implement it, to add the new record as a son of the selected record?

Thanks,
Otto Machado.

Mahalakshmi Karthikeyan [Syncfusion]
Replied On May 19, 2015 08:51 AM

Hi Otto,

Sorry for the inconvenience caused.

We would like to let you know that currently we cannot add new record as child of selected record through the API in Gantt control. We can achieve it through the “addRecord()” public method in the button click event. Please refer the below code snippet for details.

@Html.EJ().Button("text").Text("Add")


@(Html.EJ().Gantt("Gantt").

//…

ClientSideEvents(eve =>

{

eve.ActionComplete("ActionComplete");

}).

)

$("#text").click(function () {

var GanttObj = $("#Gantt").data("ejGantt");

var arg = {};

arg._cAddedRecord = {

TaskName: "New Task",

TaskId: "41",

StartDate: "02/16/2014",

Duration:"4"

}


GanttObj.addRecord(arg._cAddedRecord, ej.Gantt.AddRowPosition.Child);

});


// To update the database through add Record method

function ActionComplete(args) {


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

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

var ganttRecord = args._cAddedRecord.item;

if (args._cAddedRecord.parentItem)

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

$.ajax({

type: "POST",

url: "/Gantt/Add",//Add is Server side method

data: ganttRecord,

dataType: "json"


});


}

}

We have also prepared a sample based on this and you can find the sample under the following location:

Sample: http://www.syncfusion.com/downloads/support/forum/119177/MVCsampleSQL3291475.zip

Please let us know if you need more information on this.

Regards,

Mahalakshmi K.


Otto Moura Machado Filho
Replied On May 19, 2015 10:52 AM

I did not understand.

It used to work before the update.

That was the code, then before the last updated no code was necessary. Why can't I do it now?

I tried to use your code and it not worked. I don't have and don't want a different button to add a child. I'd like to do it using the "plus icon" button as I used to do. Isn't possible anymore?

Thanks,
Otto Machado.

Mahalakshmi Karthikeyan [Syncfusion]
Replied On May 20, 2015 09:08 AM

Hi Otto,

We regret for the inconvenience caused.

We would like to let you know that, the current behavior of the Gantt control for adding a new record using toolbar is, when the toolbar add button is clicked while a row is selected, a new row will be added as sibling below to the selected row, and when the toolbar add button is clicked when no row is selected, a new row will added to the top most position in Gantt.





According to the above snap shot, if we select “child Task 1” and click the toolbar add button then a new row will add as sibling below to the “child Task 1” record , thereby adding a child record to “Parent Task 1“.

Adding a new child record using Context Menu

Rather if the requirement is only to add a child record , then we can customize the context menu to add a new task as child in Gantt , by appending a custom context menu item to the context menu . Please refer the below code snippet to enable and customize the context menu.

@(Html.EJ().Gantt("Gantt").

//…

.EnableContextMenu(true)

.ClientSideEvents(eve =>

{

eve.ActionComplete("ActionComplete");

eve.ContextMenuOpen("contextMenuOpen");

}).

)

<script type="text/javascript">


function contextMenuOpen(args) {

args.contextMenuItems.push(

{

headerText: "Add New Child",

menuId:"AddChild",

eventHandler: function () {

var GanttObj = $("#Gantt").data("ejGantt");

var arg = {};

arg._cAddedRecord = {

TaskName: "New Task",

TaskId: "41",

StartDate: "02/16/2014",

Duration: "4"

}

GanttObj.addRecord(arg._cAddedRecord, ej.Gantt.AddRowPosition.Child);

}

});

}

function ActionComplete(args) {


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

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

var ganttRecord = args._cAddedRecord.item;

if (args._cAddedRecord.parentItem)

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

$.ajax({

type: "POST",

url: "/Gantt/Add",//Add is Server side method

data: ganttRecord,

dataType: "json"


});


}

}


We have also modified the previous sample according to this and please find the sample under the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/119177/addRecord581440189.zip


We have also logged feature for providing various row positions (below , above , as child) for adding a new record , with a popup when the toolbar add button is clicked.

Please let us know if you need more information on this.

Regards,

Mahalakshmi K.


Otto Moura Machado Filho
Replied On May 21, 2015 10:52 AM

Some things changed after the last updated.

I tried your implementation of "Add New Child" on ContextMenu and it helps. I have tried to hide the other items and show only the "Add New Child" button, but when I hide the other buttons, the new button don't work.

And another key ponint: You said that when adding a new row using "Add" button insert a new row as a sibling exactly below the selected row.

So it was not like this on my code. Then I tried it on the sample you send me.

So the Behaviour was the same. I will explain, and you can see it on the examples attached.

I selected the TaskID 11 ("New Task") and clicked the "Add" button (the same occurs if i use "Add Row Below" by using the ContextMenu), as you can see in the Example1 file.

Then Gantt inserted a new row belox called "New Task 19", and it's ok. (Example2 file)

But after reload the page, the task is moved and now it is the "last sibling" as you can see in the Example3 file.

So, is there a bug?

Any solution to correct it?

Remembering that this test was in the code you send me in this mail.

Thanks,
Otto Machado.

Attachment: Example_4f2eda5b.zip

Mahalakshmi Karthikeyan [Syncfusion]
Replied On May 22, 2015 09:10 AM

Hi Otto,

Sorry for the inconvenience caused.

Query 1: I have tried to hide the other items and show only the "Add New Child" button, but when I hide the other buttons, the new button don't work.

Solution: we would like to let you know that we are not able to reproduce the issue. We suggest you to remove the context menu items by following the below code snippet.

function contextMenuOpen(args) {

args.contextMenuItems.splice(0, 4);

args.contextMenuItems.push(


{


headerText: "Add New Child",

menuId:"AddChild",


eventHandler: function () {


var GanttObj = $("#Gantt").data("ejGantt");

var arg = {};

arg._cAddedRecord = {

TaskName: "New Task",

TaskId: "41",

StartDate: "02/16/2014",

Duration: "4"

}


GanttObj.addRecord(arg._cAddedRecord, ej.Gantt.AddRowPosition.Child);


}


});


}

We have also prepared a sample based on this. And you can find the sample under the below location.

Sample: http://www.syncfusion.com/downloads/support/forum/119177/addRecord1962133021.zip

Query 2: But after reload the page, the task is moved and now it is the "last sibling" as you can see in the Example3 file.

Solution: We would like to inform you that this is not a bug and this behavior is not changed from Volume 1(13.1.0.21), this behavior even exists in Volume 1 release. Since we are using self-reference data source to map the properties from the SQL data, we cannot make it order the records while we inserting a new record. While adding a new record, the Gantt control passes the newly added record to the server from the view , and it is then inserted into SQL database using “INSERT INTO” SQL query , but without any specific order and after refreshing the SQL database Gantt control just retrieves the data from SQL database and renders it , unless we pass the datasource object in a specific order Gantt control renders the data from database in default order . But We can achieve this in the view by collecting all the records from the controller and make it order then we can push it to the Gantt to make sense.

We are working on this sample and we will provide a workaround sample for this behavior in a business day(25/05/2015).

Please let us know if you need more information on this.

Regards,

Mahalakshmi K.


Mahalakshmi Karthikeyan [Syncfusion]
Replied On May 25, 2015 09:27 AM

Hi Otto,

Sorry for the inconvenience caused.

We would like to let you know that we cannot insert into the SQL database in particular position using “INSERT INTO” Query. When we add an item in Gantt , initially we add the item in UI at a specific row position for instance below the selected row , and in the process behind UI , we used to push the newly added item in the SQL database using AJAX post method , now the newly added item will be inserted in the SQL database at the system allocated space , Now when the browser is refreshed the Gantt is rendered using the data from the datasource . The Gantt renders whatever the data returns from the controller. There is no hierarchy of order in the self-Reference data source, the child items of the particular parent renders just by its parent Id and not by its position. So we cannot position the items inside the parent.

Regards,

Mahalakshmi K.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;