0

i am using the ejtreegrid to display and edit my hierarchical data . also i am using the actionComplete event to send data to my asp.net controller to persist data . here the code of my controller :

  public int AddFamille(string DESIGNATION)
        {


            FAMILLE f = new FAMILLE()
            {

                FA_DESIGNATION = DESIGNATION,
                FA_ID_PARENT = 1};
                ctx.FAMILLES.Add(f);
                ctx.SaveChanges();

            return f.ID_FAMILLE;
        }

it return the ID of the newly added entity , i have checked that and it's ok .

on the client side here the ajax call

function OnactionComplete(args) {
  if (args.requestType == "addNewRow") {
                    var item = args.addedRow;

                    $.ajax({
                        type: "POST",
                        url: '/Admin/AddFamille?`DESIGNATION='+item.DESIGNATION,`

                        success: function (data) {
                            args.addedRow.ID= data;
                        }
                    });
                }
}

as you can see i am trying replace the added item ID with the new ID that came from the server, but unfortunally it has no effect .

any idea is welcome . thanks

user2475096
  • 350
  • 3
  • 19

1 Answers1

0

By using “refreshRow” public method we can refresh the specific row in TreeGrid.

Please find the code example below:

function actionComplete(eventArgs) {          
        var treeObj = this,
            //To get the index of newly added row
            addedRow = treeObj.model.selectedItem;
        if (eventArgs.requestType === 'addNewRow') {                
            //Newly Added Record is obtained here , which can be updated to database
            var addedRecord = eventArgs.addedRow;
            $.ajax({
                type: "POST",
                data: { Name: addedRecord.TaskName },
                dataType: "json",                   
                url: "/TreeGrid/Add",//Add is Server side method
                success: function (result) {                       
                    addedRow.TaskId = addedRow.item.TaskId = result;
                    //To refresh the newly added row
                    treeObj.refreshRow(treeObj.model.updatedRecords.indexOf(addedRow));
                },
            });
        }
    }

Please find the sample from below location

Sample

Regards,

Syncfusion Team

  • thanks for the sample, really appreciate but unfortunally it didn't the trick .i have a console error in the line addedRow.TaskId = addedRow.item.TaskId = result; the property item is undefined – user2475096 Nov 22 '16 at 19:31
  • btw i am using the javascript version of the control not the .net mvc one – user2475096 Nov 22 '16 at 19:32