Hi,
In my current implementation I have a page that is set up as stated in my previous post:
https://www.telerik.com/forums/autobind(false)-not-adding-a-new-row-when-grid-is-empty
The above implementation sets up my datasource in the initialization of the grid and populates the grid with the data from the API.
What am I trying to achieve?
I am looking for a way to design 2 sets of datasources and apply the selected datasource to the grid based on a button click.
My current attempt looks like this:
@(Html.Kendo()
.Grid<CoreMVC.ViewModels.SysuserViewModel>()
.Name("grid")
.Columns(columns =>
{
...
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.EndsWith("Ends with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
.Contains("Contains")
.DoesNotContain("Doesn't contain")
))
)
.Pageable()
.Navigatable()
.ColumnMenu()
.AutoBind(false)
.Sortable()
.Editable()
.Resizable(resizable => resizable.Columns(true))
.Scrollable(scr => scr.Height(800))
.Reorderable(reorderable => reorderable.Columns(true))
.DataSource("dataSource1")
)
@(Html.Kendo().DataSource<CoreMVC.ViewModels.SysuserViewModel>()
.Name("dataSource1")
.Ajax(dataSource => dataSource
.PageSize(10)
.Model(m =>
{
m.Id(p => p.userid);
m.Field(p => p.role).DefaultValue(ViewData["defaultRole"] as CoreMVC.ViewModels.RoleViewModel);
})
//.Events(ev => ev
//.Error("error_handler")
//.Push("onPush")
//.Sync("sync_handler")
//)
.Read(read => read
.Url(Base.APIHostAddress + "/api/user/getall")
.Type(HttpVerbs.Get)
)
)
)
This datasource successfully hits my API and returns JSON but the grid is not populated and there is no error message. Is this because I am not specifying a DataType as "json" on the datasource? If so, I am unable to find the correct place to state the datatype with this datasource.
The return of the API looks like this: "return Json(userList);" where userList isa List<userDTO>.
I have commented out the events, but i am also receiving errors on the events saying that the methods cannot be found even though they are present and work when I use the implementation from the forum post i created stated above.
Thank you in advance!