BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
[aspx]
<script type="text/javascript">
$(function () {
var dataManager = ej.DataManager({
url: "/TreeGrid.aspx/GetTreeGridData",
adaptor: "UrlAdaptor"
});
$("#treeGrid").ejTreeGrid({
dataSource: dataManager,
endEdit: function (args) {
//To update after editing TreeGrid
var editedRecord = args.data.item;
PageMethods.UpdateIt(editedRecord);
},
actionComplete: function ActionComplete(args) {
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);
}
}
}
});
});
//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];
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);
}
}
} |
[aspx.cs]
//we need to pass the servername,database name, username and password to connect the mySql server
string con_string = "Server=localhost;Database=tgrid;Uid=root;Pwd=Treegrid";
[WebMethod]
public void Update(TaskData Task)
{
MySqlConnection con;
MySqlCommand command;
con = new MySqlConnection(con_string);
command = con.CreateCommand();
command.CommandText = "UPDATE gantt SET taskName='" + Task.Name + "', startDate='" + Task.StartDate + "', duration='" + Task.Duration + "' WHERE taskID='" + Task.Id + "'";
con.Open();
command.ExecuteNonQuery();
con.Close();
}
public void Add(TaskData Task)
{
MySqlConnection con;
MySqlCommand command;
con = new MySqlConnection(con_string);
command = con.CreateCommand();
command.CommandText = "INSERT INTO gantt SET taskID='" + Task.Id + "', taskName='" + Task.Name + "', startDate='" + Task.StartDate + "',duration='" + Task.Duration + "',parentID='"+Task.ParentId + "'";
con.Open();
command.ExecuteNonQuery();
con.Close();
}
public void Delete(TaskData Task)
{
MySqlConnection con;
MySqlCommand command;
con = new MySqlConnection(con_string);
command = con.CreateCommand();
command.CommandText = "DELETE FROM gantt WHERE taskID='" + Task.Id + "'";
con.Open();
command.ExecuteNonQuery();
con.Close();
} |
Hi Andres,Thanks for contacting Syncfusion supportQuery 1 I would like to see a complete example of treegrid in javascript with connections to "mysql" db which have functions crudSolution: We have prepared the workaround and rendered the TreeGrid with mySql database.And by using the “actionComplete” and “endEdit” client side events in TreeGrid we can update the data base during insert, update and delete action.Please find the code example below:
[aspx]<script type="text/javascript">$(function () {var dataManager = ej.DataManager({url: "/TreeGrid.aspx/GetTreeGridData",adaptor: "UrlAdaptor"});$("#treeGrid").ejTreeGrid({dataSource: dataManager,endEdit: function (args) {//To update after editing TreeGridvar editedRecord = args.data.item;PageMethods.UpdateIt(editedRecord);},actionComplete: function ActionComplete(args) {if (args.requestType === 'addNewRow') {//Newly Added Record is obtained here , which can be updated to databaseaddedRecord = 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 tooif (data.hasChildRecords) {deleteChildRecords(data);}}}});});//Delete inner level child recordsfunction 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);}}}Please find the code example below for sever side methods to render the TreeGrid with mySql database
[aspx.cs]//we need to pass the servername,database name, username and password to connect the mySql serverstring con_string = "Server=localhost;Database=tgrid;Uid=root;Pwd=Treegrid";[WebMethod]public void Update(TaskData Task){MySqlConnection con;MySqlCommand command;con = new MySqlConnection(con_string);command = con.CreateCommand();command.CommandText = "UPDATE gantt SET taskName='" + Task.Name + "', startDate='" + Task.StartDate + "', duration='" + Task.Duration + "' WHERE taskID='" + Task.Id + "'";con.Open();command.ExecuteNonQuery();con.Close();}public void Add(TaskData Task){MySqlConnection con;MySqlCommand command;con = new MySqlConnection(con_string);command = con.CreateCommand();command.CommandText = "INSERT INTO gantt SET taskID='" + Task.Id + "', taskName='" + Task.Name + "', startDate='" + Task.StartDate + "',duration='" + Task.Duration + "',parentID='"+Task.ParentId + "'";con.Open();command.ExecuteNonQuery();con.Close();}public void Delete(TaskData Task){MySqlConnection con;MySqlCommand command;con = new MySqlConnection(con_string);command = con.CreateCommand();command.CommandText = "DELETE FROM gantt WHERE taskID='" + Task.Id + "'";con.Open();command.ExecuteNonQuery();con.Close();}We have also prepared the sample to render the TreeGrid using mySql database with ASP as the code behind. Please find the sample from below location:Please find our Knowledge base to render the TreeGrid with MySql Database using PHP.Disclaimer: Please refer the MySql.Data.dll to render the TreeGrid with mysql data base.Query2: I perform this request because I cannot find good documentation on this controlSolution:We are currently enhancing our online documentation. It will available at the end of October 2016.Please let us know if you require further assistance on this.
Regards,
Jone sherine P S
Query |
Response | |
To create a new row does not show me the "taskid" (autoincrement) |
At present there is no support to auto increment the taskId while we adding a new record. For this we have already logged a feature request regarding this. It will be implemented in any of our upcoming main release. | |
if I press the esc key to exit, I delete the row |
1. As per the current behavior, if we press the “esc” key before saving the newly added record then it deletes the newly added record.
2. While rendering the TreeGrid with mySql database the taskId should be unique.
3. If incase another record having the taskId similar to the newly added record’s taskId that record will also be deleted along with newly added record after pressing “esc” key. | |
When I drag a row to acerla daughter of another, delete my record |
We have prepared the work around and updated the mySql database during drag and drop action using “rowDrag” and “rowDragStop” client side events.
Please find the code example below:
We have also prepared the sample for your reference. Please find the sample from the below location.
|
Server side |
Client side | ||
DataBinding:
|
| ||
Update:
|
| ||
Add:
|
| ||
Delete:
|
|
Server side |
Client side | ||
DataBinding:
|
| ||
Update:
|
| ||
Add:
|
| ||
Delete:
|
|