Skip to main content

MVCxGanttItemUpdateValues<TItem, TKey>.MapInsertedItemKey(TItem, TKey) Method

Specifies the key value of the inserted item.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.1.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public void MapInsertedItemKey(
    TItem item,
    TKey itemKey
)

Parameters

Name Type Description
item TItem

The inserted item.

itemKey TKey

The inserted item’s key.

Remarks

The Gantt extension builds a Gantt chart based on the items’ key values.

The extension retrieves keys for all bound items (tasks, dependencies and others) from a data source. If a new item is created by a user, you should obtain the item’s key and send it to the extension. The key can be autogenerated by a data source on item inserting, or created manually in code. Call the MapInsertedItemKey method for each created/inserted data item to map keys to items.

The GetBatchUpdateResult method combines all mapped keys and returns them as an action result to the client instance of the Gantt extension.

Note

If an item’s key is not determined, the “The inserted item key is undefined. Use the MVCxGanttItemUpdateValues.MapInsertedItemKey method to specify the key value for a newly inserted {2}.“ exception is thrown.

Partial View:

@Html.DevExpress().Gantt(settings => {
    settings.BatchUpdateRouteValues = new { Controller = "Features", Action = "GanttBatchUpdate" };
    // ...
}).Bind(
    GanttDataProvider.Tasks, 
    GanttDataProvider.Dependencies, 
    GanttDataProvider.Resources, 
    GanttDataProvider.ResourceAssignments
).GetHtml()

Controller Code:

public ActionResult GanttBatchUpdate(
    MVCxGanttTaskUpdateValues<Task, string> taskUpdateValues){
    ProcessTaskValues(taskUpdateValues);
    return GanttExtension.GetBatchUpdateResult(taskUpdateValues, dependencyUpdateValues);
}

void ProcessTaskValues(MVCxGanttTaskUpdateValues<Task, string> taskUpdateValues) {
    foreach(var item in taskUpdateValues.Update)
        GanttDataProvider.UpdateTask(item);
    foreach(var itemKey in taskUpdateValues.DeleteKeys)
        GanttDataProvider.DeleteTask(itemKey);
    foreach(var item in taskUpdateValues.Insert) {
        taskUpdateValues.MapInsertedItemKey(item, GanttDataProvider.InsertTask(item));
    }    
}

Online Demo

Gantt - Data Binding and Modification

See Also