BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hi Otto,
We can update our predecessor field of the reference rows that connected with deleted task item to the database by retrieving the corresponding updated TaskId and Predecessor values of the rows from the Gantt data source and it can be updated to the database with the help of AJAX POST method in the controller.
Please refer the below code snippets for more details.
Code snippets:
In Index.cshtml:
@(Html.EJ().Gantt("Gantt"). //...
ClientSideEvents(eve => { eve.ActionComplete("ActionComplete"); }). Datasource(ViewBag.dataSource) ) @(Html.EJ().ScriptManager())
<script type="text/javascript">
function ActionComplete(args) {
//... else if (args.requestType === 'delete') { // To delete a Task item
var ganttRec = args.data.item; $.ajax({ type: "POST", url: "/Gantt/Delete", //Update is Server side method data: ganttRec, dataType: "json", });
// To update the predecessors of the reference rows if (args.data.predecessor) { var param = [], datalinks,links, j = 0; for (var i = 0; i < args.data.predecessor.length; i++) { if (args.data.predecessor[i].to != args.data.taskId) {
var updateId = args.data.predecessor[i].to; for (var k = 0; k < args.model.dataSource.length; k++) { if (updateId == args.model.dataSource[k].TaskId) { var links = args.model.dataSource[k].Predecessor;
param[j] = { linkId: updateId, linkString: links };
j++;
} } } }
}
$.ajax({ contentType: 'application/json; charset=utf-8', type: "POST", url: "/Gantt/UpdatePredecessors", //Update is Server side method data: param, dataType: "json",
});
} |
In GanttController.cs:
public class GanttController : Controller { //... [HttpPost()] public void UpdatePredecessors(List<TaskLinks> Items) {
connectionString = string.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + Server.MapPath("App_Data") + @"\GanttDatabase2008.mdf;Integrated Security=True;Connect Timeout=30"); SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString con.Open(); for (int i = 0; i < Items.Count; i++) { int IDNumber = Items[i].LinkId;
string cmdString = "UPDATE GanttData1 SET Predecessor=@Predecessor WHERE TaskId = '" + IDNumber + "'";
using (SqlCommand sqlCommand = new SqlCommand(cmdString, con)) {
if (Items[i].LinkString == null) { sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString).Value = ""; } else { sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString); }
sqlCommand.ExecuteNonQuery(); } } con.Close(); }
} |
Please let us know if you require further assistance on this.
Regards,
John. R