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

[Solved] Master/Detail with Ajax binding to a DataTable is not supported?

1 Answer 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Svetlana
Top achievements
Rank 1
Svetlana asked on 18 Jul 2012, 01:43 AM

Hi,

 

I am trying to implement Master/Detail Ajax Hierarchy with batch editing on details grid.

And I am trying to use DataTable as a datasource for a child grid.


View looks like this:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DataTable>" %>
<%@ Import Namespace="System.Data" %>
  
<% Html.Telerik().Grid<EmployeeTimesheet.Models.Employee>()
        .Name("EmployeeGrid")
        .DataBinding(dataBinding => dataBinding.Ajax().Select("GetEmployeeList", "Timesheet"))
        .DataKeys(d => { d.Add(fk => fk.EmployeeId).RouteKey("EmployeeId"); })
        .Columns(columns =>
        {
            columns.Bound(o => o.EmployeeId);
            columns.Bound(o => o.FirstName);
            columns.Bound(o => o.LastName);
            columns.Bound(o => o.FTE);
        })
  
  
        .DetailView(details => details.ClientTemplate(
                Html.Telerik().Grid(Model)
                    .Name("DailyTimesheetData_<#= EmployeeId #>")
                    .Columns(columns =>
                    {
                        columns.Bound("timesheet_data_id");
                        columns.Bound("timesheet_date");
                        columns.Bound("start_time");
                        columns.Bound("end_time");
                        columns.Bound("lunch_duration");
                        columns.Bound("hours_worked");
                    })
                    .DataKeys(d =>
                    {
                        d.Add("timesheet_data_id").RouteKey("timesheet_data_id");
                    })
                    .ClientEvents(events =>
                                events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError"))
                    .Editable(editing => editing.Mode(GridEditMode.InCell))
                    .ToolBar(commands => { commands.SubmitChanges(); })
                    .DataBinding(dataBinding => dataBinding.Ajax()
                        .Select("GetTimesheetForEmployee", "Timesheet", new { employeeId = "<#= EmployeeId #>" })
                        .Update("SaveTimesheetChanges", "Timesheet", new { employeeId = "<#= EmployeeId #>" })
                        )
                    .ToHtmlString()
        ))
  
  
        .RowAction(row => row.DetailRow.Expanded = true)
        .Render();
              
%>


But I am getting an error that “Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.” for a details.ClientTemplate of a child grid.

 

But batch editing works only with Ajax Binding, so I don’t have choice but to use Ajax Binding and therefore a ClientTemplate if I want batch editing.


So does that mean you don’t support a DataTable as a datasource for a Master/Details scenario with Ajax Binding?

1 Answer, 1 is accepted

Sort by
0
Svetlana
Top achievements
Rank 1
answered on 18 Jul 2012, 10:51 AM

In relation to this error: "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions" - it actually says that there no way to use Grid bound to a DataTable inside any template, e.g. inside a cell as part of row template or as a child grid.
I tried to put a Grid inside of a cell of a column of another grid, and it worked nicely until I changed its datasource to be a DataTable - after that I am getting this above mentioned error about Templates.
So that means that a Grid bound to a DataTable may be used only as it is, with no any parent grid or not inside any cell of a grid, which is a serious restriction, I recon.
Are you going to fix that any time in the future or you are not planning to support DataTable as a datasource  the same way as you support IEnumerable collections?

Tags
Grid
Asked by
Svetlana
Top achievements
Rank 1
Answers by
Svetlana
Top achievements
Rank 1
Share this question
or