Hi
I'm not sure what am I doing wrong but I'm using Custom Datasoure (API) and adding an authorization header to the request made by the DataSource. Everything works fine but the problem is when the grid is empty I can't add a new row. I was advised to set Autobind(false) from this thread... if I set it to true add new row works fine but I get an Error 401 onload
@(Html.Kendo().Grid<
Models.IdentityView
>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.identityType).ClientTemplate("#=identityType.typename#").Width(120);
columns.Bound(p => p.number).Width(120);
columns.Command(command => { command.Destroy(); command.Edit(); }).Width(100);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Navigatable()
.ColumnMenu()
.AutoBind(false)
.Sortable()
.Scrollable(scr => scr.Height(800))
.Reorderable(reorderable => reorderable.Columns(true))
.DataSource(dataSource => dataSource
.Custom()
.PageSize(20)
.Events(events => events
.Sync("sync_handler"))
.Schema(schema => schema.Model(m =>
{
m.Id(p => p.identityid);
m.Field(p => p.identityType).DefaultValue(ViewData["defaultType"] as AdorReactUI.Models.TypeView);
}))
.Transport(transport =>
{
transport.Read(read =>
read.Url("/api/Identity/GetIdentityDetails)
.DataType("json")
.Type(HttpVerbs.Get) );
transport.Create(create =>
create.Url("/api/Identity/post")
.DataType("json")
.Type(HttpVerbs.Post)
.ContentType("application/json; charset=utf-8") );
transport.ParameterMap("parameterMap");
})
)
)
For Passing a Token
$(function () {
var grid = $("#grid").data("kendoGrid");
grid.dataSource.transport.options.read.beforeSend = Token;
grid.dataSource.transport.options.create.beforeSend = Token;
grid.dataSource.transport.options.update.beforeSend = Token;
grid.dataSource.transport.options.destroy.beforeSend = Token;
grid.dataSource.read(); // make a DataSource read, which will now use the authorization header
function Token(xhr) {
xhr.setRequestHeader('Authorization', "my token");
}
});