How to persist sort position into DB

Hi,

How to get the position and store in the database when add before or after task? The Gannt control provide the function to add before or after but after refresh data the position information lost.

Regards

1 Reply 1 reply marked as answer

PP Pooja Priya Krishna Moorthy Syncfusion Team May 25, 2021 04:00 AM UTC

Hi Michael, 
  
We can maintain the index of newly added record on refreshing the page by work-around solution. We can pass additional parameter(index) to the server side and insert the record at particular index in actionBegin event with requestType beforeAdd as like below code example. 
  
  
actionBegin: function (args) { 
    if (args.requestType == "beforeAdd") { 
          let obj = (document.getElementById("GanttContainer") as any).ej2_instances[0]; 
          let selectedRowIndex = obj.selectedRowIndex; 
          let isToolbar = (window as any).isToolbarClick; 
          // index is set based on position of newly added record 
          if ((!isToolbar && obj.contextMenuModule.item == "Above") || obj.editSettings.newRowPosition == 'Above') { 
            obj.query = new Query().addParams('index', selectedRowIndex.toString()); 
          }      
       //... 
  }, 
  
[controller.cs] 
public IActionResult BatchUpdate([FromBody] CRUDModel batchmodel) 
{ 
   int index = 0; 
   if (batchmodel.@params != null) 
   { 
         foreach (KeyValuePair<string, object> param in batchmodel.@params) 
         { 
             index = Int32.Parse((string)param.Value); 
         } 
   } 
             
    if (batchmodel.added != null) 
    { 
       for (var i = 0; i < batchmodel.added.Count(); i++) 
       { 
            DataList.Insert(index, batchmodel.added[i]); 
       } 
      } 
    //... 
} 
  
  
  
Regards, 
Pooja K. 


Marked as answer
Loader.
Up arrow icon