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

Setting custom command button with odata.

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ddimakis
Top achievements
Rank 1
ddimakis asked on 26 Feb 2015, 01:21 PM
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>







1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 02 Mar 2015, 12:10 PM
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.

 
Tags
Grid
Asked by
ddimakis
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or