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

[Solved] Bound column to a list and loop

5 Answers 369 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.
Syed
Top achievements
Rank 1
Syed asked on 04 Jan 2012, 02:03 PM
HI,

I'm  a novice Telerik Grid user and was wondering if it is a possibility to use Telerik Grid such that I bound one column to a string array and then somehow loop through it to show the array items as list<li>.


StoreViewModel:(One store can have multiple displays)
public string Name { getset; } 
public
string[] StoreDisplays { get; set; }
Controller:
private IQueryable<StoreViewModel> GetRetailers()
{
var stores = from sg in db.Store
select new RetailerViewModel
{
  Name = sg.sg_Name,
  StoreDisplays = (   from ca in db.Categories.Where(item => item.c_ParentId == null)
               join sd in db.StoreDisplays.Where(item => item.sd_StoreGroupId == sg.sg_Id) on ca.c_Id equals sd.sd_CategoryId into gj
               from subpet in gj.DefaultIfEmpty()
               select (ca.c_Name)).ToArray<string>()
};
return stores;
}



Index.aspx
<%= Html.Telerik().Grid<StoreLocatorBackOffice.Models.RetailerViewModel>(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(sg => sg.Name)
            columns.Bound(sg => sg.StoreDisplays);
        })
        .DataBinding(dataBinding => dataBinding
                .Ajax()
                    .Select("_Index", "Retailer", true)
        )
        .Scrollable(scrolling => scrolling.Enabled(false))
        .Sortable(sorting => sorting
            .OrderBy(sortOrder => sortOrder.Add(p => p.Name).Ascending()))
        .Pageable(settings => settings.PageSize((int)ViewData["pageSize"]))
        .Filterable(filtering => filtering.Enabled(true))
        .Footer(true)
        %>



Currently it Displays like this.

Name              Store Display
Store#1           Display#1Display#2Display#6
Store#2           Display#3Display#9

And want to some how show it as follows.

Name              Store Display
Store#1           Display#1
                       Display#2
                       Display#6

Store#2           Display#3
                       Display#9

5 Answers, 1 is accepted

Sort by
0
Syed
Top achievements
Rank 1
answered on 05 Jan 2012, 09:14 AM
Wondering if it is even possible at all?
0
Petur Subev
Telerik team
answered on 05 Jan 2012, 01:27 PM
Hello Syed,

Yes it is possible, to achieve it you need to set a ClientTemplate which iterates through the data and format it the desired way.
For your convenience I attached a sample project which might come on handy.

Greetings,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Robert Enestedt
Top achievements
Rank 1
answered on 05 Jan 2012, 02:26 PM
 
0
Syed
Top achievements
Rank 1
answered on 05 Jan 2012, 06:19 PM

Hi,

Thanks for your response, it solves the problem.
One thing I notice now is that sorting and filtering on that column is not working, Is it a limitation of Telerik Grid or it could be changed programatically.
I've attached the text from exception.

I'm getting the value of variable like as follows from the controller.

StoreDisplays = String.Join(",", (from sd in db.StoreDisplays.Where(item => item.sd_StoreGroupId == sg.sg_Id)
 from ca in db.Categories.Where(item => item.c_Id == sd.sd_CategoryId).DefaultIfEmpty()
 select (ca.c_Name.ToString())).ToArray<string>())

The reason I'm using String.Join is that when I used string[] array, it complained that sorting cannot be applied on arrays, So now I worked around to take a comma separated string and then split it inside the column template. But now I get the following exception.

Wondering If sorting and filtering can be applied to template columns?


Method 'System.String Join(System.String, System.String[])' has no supported translation to SQL
 
Server Error in '/' Application
 
Method 'System.String Join(System.String, System.String[])' has no supported translation to SQL.
 
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.NotSupportedException: Method 'System.String Join(System.String, System.String[])' has no supported translation to SQL.
 
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 
                  
[NotSupportedException: Method 'System.String Join(System.String, System.String[])' has no supported translation to SQL.]
   System.Data.Linq.SqlClient.Visitor.TranslateStringStaticMethod(SqlMethodCall mc) +490599
   System.Data.Linq.SqlClient.Visitor.VisitMethodCall(SqlMethodCall mc) +608
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +2136
   System.Data.Linq.SqlClient.SqlVisitor.VisitExpression(SqlExpression exp) +11
   System.Data.Linq.SqlClient.SqlVisitor.VisitSelectCore(SqlSelect select) +268
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +20
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1015
   System.Data.Linq.SqlClient.SqlVisitor.VisitAlias(SqlAlias a) +16
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +430
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +11
   System.Data.Linq.SqlClient.SqlVisitor.VisitSelectCore(SqlSelect select) +26
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +20
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1015
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, ReadOnlyCollection`1 parentParameters, SqlNodeAnnotations annotations) +805
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +155
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +132
   System.Data.Linq.DataQuery`1.System.Collections.IEnumerable.GetEnumerator() +32
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +61
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1380
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeDictionary(IDictionary o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +527
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1319
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +26
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +74
   System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +231
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +264
   System.Web.Mvc.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +345
   System.Web.Mvc.Controller.ExecuteCore() +115
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +42
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
 
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +43
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
 
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969117
 
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
 
[NotSupportedException]: Method 'System.String Join(System.String, System.String[])' has no supported translation to SQL.
   at System.Data.Linq.SqlClient.PostBindDotNetConverter.Visitor.TranslateStringStaticMethod(SqlMethodCall mc)
   at System.Data.Linq.SqlClient.PostBindDotNetConverter.Visitor.VisitMethodCall(SqlMethodCall mc)
   at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
   at System.Data.Linq.SqlClient.SqlVisitor.VisitExpression(SqlExpression exp)
   at System.Data.Linq.SqlClient.SqlVisitor.VisitSelectCore(SqlSelect select)
   at System.Data.Linq.SqlClient.PostBindDotNetConverter.Visitor.VisitSelect(SqlSelect select)
   at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
   at System.Data.Linq.SqlClient.SqlVisitor.VisitAlias(SqlAlias a)
   at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
   at System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source)
   at System.Data.Linq.SqlClient.SqlVisitor.VisitSelectCore(SqlSelect select)
   at System.Data.Linq.SqlClient.PostBindDotNetConverter.Visitor.VisitSelect(SqlSelect select)
   at System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
   at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, ReadOnlyCollection`1 parentParameters, SqlNodeAnnotations annotations)
   at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Collections.IEnumerable.GetEnumerator()
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeDictionary(IDictionary o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
   at System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
 
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Thanks.

0
Petur Subev
Telerik team
answered on 06 Jan 2012, 11:07 AM
Hello Syed,

Sorting and filtering is not supported for template columns. You need to bind it to some property so the filtering and sorting will be applied to it and set its template.

Kind regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Syed
Top achievements
Rank 1
Answers by
Syed
Top achievements
Rank 1
Petur Subev
Telerik team
Robert Enestedt
Top achievements
Rank 1
Share this question
or