Hello,
I am surprised this is not asked about more in the forums on using JavaScript functions in view components.
I have a grid inside a view component and am having issues getting the datasource read Data function to work so I can pass parameters from the view component's backend .cs file to my API (it says grid_getReadParameters is undefiend even though it's defined in script tag at the bottom of the view component). I have read that view components can't really have javascript or something strange like that which makes no sense. I defined a script section in my view component and it was unable to find "grid_getReadParameters". How does one define this within the view component? I do not want to have to sprinkle this around on every page which uses my view component, that would defeat the purpose. Thanks in advance for your help.
See below example:
@(Html.Kendo()
.Grid<ViewModels.MyViewModel>()
.Name("grid_" + uniqueId)
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Filterable()
.ToolBar(x =>
{
x.Create().Text("Add New");
x.Save().SaveText("Save").CancelText("Cancel");
})
.Columns(columns =>
{
columns.Bound(c => c.Value)
.Width(125)
.Filterable(ftb => ftb.Multi(true).Search(true).CheckAll(true));
})
.DataSource(ds => ds
.Ajax()
.Batch(true)
.ServerOperation(false)
.Read(r => r.Url("/api/ControllerName?handler=MethodName").Data("grid_getReadParameters"))
.Events(events => events.Error("grid_error"))
.PageSize(100)
.Model(m =>
{
m.Field(id => id.Value).Editable(true);
})
)
)
So turns out I was able to avoid the javascript and just pass this for the URL for the read function:
/api/ControllerName/methodName?propertyName=value
The problem now is that I need to send over data items when I create and update records which requires sending complex objects so I still need javascript to work right for this without defining the javascript outside the view component