Setting custom command button with odata.

2 posts, 0 answers
  1. ddimakis
    ddimakis avatar
    4 posts
    Member since:
    Feb 2015

    Posted 26 Feb 2015 Link to this post

    Hi,

    In the following code snippet you see that we are using the MVC Wrapper of kendo ui grid with odata mechanism that gets its data from a controller in server side.
    We want to use custom command buttons but we are getting an exception that says that we cannot use custom commands if we are not using server binding. But when we are using odata mechanism with data binding at controller stage, why this is not a server binding ?

    Please help.

    Thanks.

    <div>
        @(Html.Kendo().Grid<Item>()
              .Name("grid")
              .Columns(columns =>
              {
                  columns.Bound(c => c.ItemCode);
                  columns.Bound(c => c.ItemName);
                  columns.Command(command => command.Custom("Details").Text("Details").Action("OpenDetailsForm", "Home")).Width(100);
              })
              .HtmlAttributes(new { style = "height: 380px;" })
              .Scrollable()
              .Selectable(o => o.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Row))
              .Sortable()
              .Resizable(o => o.Columns(true))
              .Reorderable(o => o.Columns(true))
              .Filterable()
              .Pageable(pageable => pageable
              .Refresh(true)
              .PageSizes(true)
              .ButtonCount(3))
              .DataSource(dataSource => dataSource
              .Custom()
              .ServerSorting(true)
              .ServerFiltering(true)
              .ServerPaging(true)
              .ServerGrouping(true)
              .ServerAggregates(true)
              .Schema(s => s.Total("Total").Data("Data"))
              .Type("odata")
              .PageSize(10)
              .Transport(r => r.Read(c => c.Cache(true)).Read(a => a.Action("GetGridDataSource", "Home", new { entityName = typeof(Item).FullName }).DataType("json")))))
    </div>







  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 02 Mar 2015 Link to this post

    Hello MARIANNA,

    Custom commands can be used no matter what the binding mechanism is, however the Action method can be used only with server binding. In the current case I would suggest specifying a Click event handler instead: 
    columns.Command(command => command.Custom("Details").Text("Details").Click("myCustomFunction")).Width(100);
    Once the button is clicked the myCustomFunction will be called, so you can use it to navigate to the appropriate URL.
    On a related note, you can check documentation for the differences between Server and Ajax binding.

    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top