Hello Telerik Team !
I'm using telerik gantt chart for MVC
i want to ask can i manipulate tasks data before it get's bind to the chart ?
like when READ action for task data source gets fired and get the data from server and then at client side before binding tasks to chart it can be changed.
can i do that ? kindly tell.
Thank You.
5 Answers, 1 is accepted
Yes you can manipulate the data recived from the remote by specifying a schema.parse function for the Gantt DataSource. Note, that in order to be able to configure the Parse() function, you will have to use a Custom DataSource for the Gantt HTML helper:
.DataSource(d => d
.Custom()
.Schema(s => s
.Model(m =>
{
m.Id(f => f.TaskID);
m.Field(
"title"
,
typeof
(
string
)).From(
"Title"
);
m.Field(
"start"
,
typeof
(DateTime)).From(
"Start"
);
m.Field(
"end"
,
typeof
(DateTime)).From(
"End"
);
m.Field(
"parentId"
,
typeof
(
int
)).From(
"ParentID"
);
m.Field(
"OrderId"
,
typeof
(
int
)).From(
"OrderId"
);
m.Field(
"expanded"
,
typeof
(
int
)).From(
"Expanded"
).DefaultValue(
true
);
})
.Parse(@<text>function (data) {
// configure a parse function only if the response (data) must be
// transformed in some way before data binding
return
data;
}</text>)
.Data(
"Data"
)
)
.Transport(t => t
.Read(
"ReadTasks"
,
"Task"
)
.Create(
"CreateTask"
,
"Task"
)
.Destroy(
"DestroyTask"
,
"Task"
)
.Update(
"UpdateTask"
,
"Task"
)
)
)
Note, that all fields should be properly described in the Model section. Further information on that topic could be found in our Documentation.
Regards,
Veselin Tsvetanov
Progress Telerik
can same thing happen in Resources ? i mean before opening the resources dialog box i can make change in datasource then let it append in dialogbox?
Yes, the same could be applied to for the Gantt Resources datasource too:
.Resources(r => r
.Field(
"resources"
)
.DataColorField(
"Color"
)
.DataTextField(
"Name"
)
.DataSource(d => d
.Custom()
.Schema(s => s
.Model(m => m.Id(
"ID"
))
.Data(
"Data"
)
.Parse(@<text>function (data) {
// configure a parse function only if the response (data) must be
// transformed in some way before data binding
return
data;
}</text>)
)
.Transport(t =>
{
t.Read(
"ReadResources"
,
"Gantt"
);
})
)
)
Regards,
Veselin Tsvetanov
Progress Telerik
hey . i was trying to get the assignments for the particular task in OnEdit event and in OnSave event. i was able to get only the resources but not the assignments for that task ?
i mean if i have one assigned resource coming from database and that is checked in resources dialog box. if I check one more resource and hit have button of task dialog box in OnSave event i'm getting the resource only which was coming from database. not the new one which i checked and hit save button. how can i get the new assigned resources ? i have not seen any Assignment property in my selected task as well.
The newly added assignments will be present in the values field of the evenArgs object of the save event handler of the widget:
function
onSave(e) {
var
values = e.values;
var
addedResources = values.resources;
console.log(addedResources);
};
Regards,
Veselin Tsvetanov
Progress Telerik