This is a migrated thread and some comments may be shown as answers.

AutoBind(false) not adding a new row when grid is empty

1 Answer 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 17 Jul 2018, 12:00 PM
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");
    }
});

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 20 Jul 2018, 08:16 AM
Hi Adam,

I tried reproducing the problem in the attached project, but even when the Grid has AutoBind(false) setting, row creation using addRow method works on my side. Could you try modifying my project to reproduce the issue?

Also, one thing that I did not understand from your description is whether the problem is with showing the new empty row in the Grid or with the subsequent save to the server. If there is an issue with showing the new row, then there might be some JavaScript error preventing it. If the row fails to save, I suggest that you check the browser developer tools (F12 key) Network tab to see what is the response from the server after the Grid tries to save the new row.

Regards,
Tsvetina
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
n/a
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or