We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid not showing data from datamanager

I have the following in a view:

@(Html.EJ().DataManager("Data")
    .URL("/api/Products/")
    .Adaptor(AdaptorType.WebApiAdaptor)
)

@(Html.EJ().Grid<BreadfarmBMS.Models.Product>("GridContainer")
    .DataManagerID("Data")
    .Query("new ej.Query().take(5)")

    .AllowSorting()
    .AllowTextWrap()
    .AllowPaging()

    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog); })

    .IsResponsive()

    .ToolbarSettings(toolbar =>
            toolbar.ShowToolbar()
            .ToolbarItems(items =>
            {
                items.AddTool(ToolBarItems.Add);
                items.AddTool(ToolBarItems.Edit);
                items.AddTool(ToolBarItems.Delete);
                items.AddTool(ToolBarItems.Update);
                items.AddTool(ToolBarItems.Cancel);
                items.AddTool(ToolBarItems.Search);
            }))

    .Columns(col =>
    {
        col.Field("ProductID").HeaderText("ID").IsIdentity(true).Visible(false).Add();
        col.Field("Name").HeaderText("Name").Add();
    })
)

I know that the webapi data source is being called, and returning a PageResult with a valid count and records. However, the grid doesn't show any data. What am I missing? I can send a sample project if it will help.

5 Replies

JK Jayaprakash Kamaraj Syncfusion Team November 10, 2016 02:11 PM UTC

Hi Brian, 
 
Thank you for contacting Syncfusion support. 
 
We have created a sample with your code example but we were unable to reproduce the issue at our end. Please share the following information to find the cause of the issue.    
                                                                                                                
1.     Is there any script error or exception thrown in your project? If so, attach the screenshot of your stack trace.    
2.     Attach screenshot of the POST request in Network tab of browser developer tool. Please expand the post request and share the screenshot    
3.     Did you face the issue in initial rendering or any actions performed in Grid?    
4.     Share the video/screenshot to show the issue  
5.     Issue replication procedure.   
6.     Essential studio and browser details.  
7.     If possible, provide an issue reproducing sample or replicate the issue in the following sample.   
 
 
Regards, 
 
Jayaprakash K. 



RB R Brian Lindahl November 10, 2016 08:25 PM UTC

I think I found something... there's an exception returned from the webapi "get" call.

It would seem that there are differences in the linq aupport between Entity Framework and using linq to sql directly, as the sample you provided does. Since "OrderBy" isn't called if the incoming query doesn't ask for it, the call to "skip" fails.

I've worked around it (for now) by setting a default "order by" if the query isn't asking for one. Is there a way at the view level to set the default sort order for a grid, so I don't have to make that assumption in the webapi code?

Exception thrown: 'System.NotSupportedException' in EntityFramework.dll ("The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.")

>    EntityFramework.dll!PassthroughOrderByLifter.Skip(System.Data.Entity.Core.Common.CommandTrees.DbExpression k = {unknown})    C#
     EntityFramework.dll!OrderByLifter.Skip(System.Data.Entity.Core.Common.CommandTrees.DbExpressionBinding input = {unknown}, System.Data.Entity.Core.Common.CommandTrees.DbExpression skipCount = {unknown})    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Skip(System.Data.Entity.Core.Common.CommandTrees.DbExpressionBinding input = {unknown}, System.Data.Entity.Core.Common.CommandTrees.DbExpression skipCount = {unknown})    C#
     EntityFramework.dll!SkipTranslator.TranslatePagingOperator(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Data.Entity.Core.Common.CommandTrees.DbExpression operand = {unknown}, System.Data.Entity.Core.Common.CommandTrees.DbExpression count = {unknown})    C#
     EntityFramework.dll!PagingTranslator.TranslateUnary(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Data.Entity.Core.Common.CommandTrees.DbExpression operand = {unknown}, System.Linq.Expressions.MethodCallExpression call = {unknown})    C#
     EntityFramework.dll!UnarySequenceMethodTranslator.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression call = {unknown})    C#
     EntityFramework.dll!SequenceMethodTranslator.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression call = {unknown}, System.Data.Entity.Core.Objects.ELinq.SequenceMethod sequenceMethod = {unknown})    C#
     EntityFramework.dll!MethodCallTranslator.TypedTranslate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression linq = {unknown})    C#
     EntityFramework.dll!TypedTranslator`1.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.Expression linq = {unknown})    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(System.Linq.Expressions.Expression linq = {unknown})    C#
     EntityFramework.dll!UnarySequenceMethodTranslator.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression call = {unknown})    C#
     EntityFramework.dll!SequenceMethodTranslator.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression call = {unknown}, System.Data.Entity.Core.Objects.ELinq.SequenceMethod sequenceMethod = {unknown})    C#
     EntityFramework.dll!MethodCallTranslator.TypedTranslate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.MethodCallExpression linq = {unknown})    C#
     EntityFramework.dll!TypedTranslator`1.Translate(System.Data.Entity.Core.Objects.ELinq.ExpressionConverter parent = {unknown}, System.Linq.Expressions.Expression linq = {unknown})    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(System.Linq.Expressions.Expression linq = {unknown})    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(System.String (error) = Internal Error in IntelliTrace)    C#
     EntityFramework.dll!<>c__DisplayClass7.AnonymousMethod()    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(System.Func func = {unknown}, System.Data.Entity.Infrastructure.IDbExecutionStrategy executionStrategy = {unknown}, bool startLocalTransaction = {unknown}, bool releaseConnectionOnSuccess = {unknown})    C#
     EntityFramework.dll!<>c__DisplayClass7.AnonymousMethod()    C#
     EntityFramework.SqlServer.dll!System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(System.Func operation = {unknown})    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(System.String (error) = Internal Error in IntelliTrace)    C#
     EntityFramework.dll!System.Data.Entity.Core.Objects.ObjectQuery`1.AnonymousMethod()    C#
     EntityFramework.dll!System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(Newtonsoft.Json.JsonWriter writer = {unknown}, System.Collections.IEnumerable values = {unknown}, Newtonsoft.Json.Serialization.JsonArrayContract contract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty member = {unknown}, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty containerProperty = {unknown})    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(Newtonsoft.Json.JsonWriter writer = {unknown}, object value = {unknown}, Newtonsoft.Json.Serialization.JsonContract valueContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty member = {unknown}, Newtonsoft.Json.Serialization.JsonContainerContract containerContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty containerProperty = {unknown})    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter writer = {unknown}, object value = {unknown}, Newtonsoft.Json.Serialization.JsonObjectContract contract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty member = {unknown}, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty containerProperty = {unknown})    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(Newtonsoft.Json.JsonWriter writer = {unknown}, object value = {unknown}, Newtonsoft.Json.Serialization.JsonContract valueContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty member = {unknown}, Newtonsoft.Json.Serialization.JsonContainerContract containerContract = {unknown}, Newtonsoft.Json.Serialization.JsonProperty containerProperty = {unknown})    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(Newtonsoft.Json.JsonWriter jsonWriter = {unknown}, object value = {unknown}, System.Type objectType = {unknown})    C#
     Newtonsoft.Json.dll!Newtonsoft.Json.JsonSerializer.SerializeInternal(Newtonsoft.Json.JsonWriter jsonWriter = {unknown}, object value = {unknown}, System.Type objectType = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Text.Encoding effectiveEncoding = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Text.Encoding effectiveEncoding = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Net.Http.HttpContent content = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Net.Http.HttpContent content = {unknown}, System.Net.TransportContext transportContext = {unknown}, System.Threading.CancellationToken cancellationToken = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStreamAsync(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Net.Http.HttpContent content = {unknown}, System.Net.TransportContext transportContext = {unknown}, System.Threading.CancellationToken cancellationToken = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.Formatting.MediaTypeFormatter.WriteToStreamAsync(System.Type type = {unknown}, object value = {unknown}, System.IO.Stream writeStream = {unknown}, System.Net.Http.HttpContent content = {unknown}, System.Net.TransportContext transportContext = {unknown})    C#
     System.Net.Http.Formatting.dll!System.Net.Http.ObjectContent.SerializeToStreamAsync(System.IO.Stream stream = {unknown}, System.Net.TransportContext context = {unknown})    C#
     System.Net.Http.dll!System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream = {unknown}, System.Net.TransportContext context = {unknown})    C#
     System.Web.Http.WebHost.dll!<WriteBufferedResponseContentAsync>d__1b.MoveNext()    C#
     mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start(TStateMachine stateMachine = {unknown})    C#
     System.Web.Http.WebHost.dll!System.Web.Http.WebHost.HttpControllerHandler.WriteBufferedResponseContentAsync(System.Web.HttpContextBase httpContextBase = {unknown}, System.Net.Http.HttpRequestMessage request = {unknown}, System.Net.Http.HttpResponseMessage response = {unknown}, System.Web.Http.ExceptionHandling.IExceptionLogger exceptionLogger = {unknown}, System.Web.Http.ExceptionHandling.IExceptionHandler exceptionHandler = {unknown}, System.Threading.CancellationToken cancellationToken = {unknown})    C#
     System.Web.Http.WebHost.dll!System.Web.Http.WebHost.HttpControllerHandler.WriteResponseContentAsync(System.Web.HttpContextBase httpContextBase = {unknown}, System.Net.Http.HttpRequestMessage request = {unknown}, System.Net.Http.HttpResponseMessage response = {unknown}, System.Web.Http.ExceptionHandling.IExceptionLogger exceptionLogger = {unknown}, System.Web.Http.ExceptionHandling.IExceptionHandler exceptionHandler = {unknown}, System.Threading.CancellationToken cancellationToken = {unknown})    C#
     System.Web.Http.WebHost.dll!<CopyResponseAsync>d__7.MoveNext()    C#
     mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start(TStateMachine stateMachine = {unknown})    C#
     System.Web.Http.WebHost.dll!System.Web.Http.WebHost.HttpControllerHandler.CopyResponseAsync(System.Web.HttpContextBase httpContextBase = {unknown}, System.Net.Http.HttpRequestMessage request = {unknown}, System.Net.Http.HttpResponseMessage response = {unknown}, System.Web.Http.ExceptionHandling.IExceptionLogger exceptionLogger = {unknown}, System.Web.Http.ExceptionHandling.IExceptionHandler exceptionHandler = {unknown}, System.Threading.CancellationToken cancellationToken = {unknown})    C#
     System.Web.Http.WebHost.dll!<ProcessRequestAsyncCore>d__0.MoveNext()    C#
     mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start(TStateMachine stateMachine = {unknown})    C#
     System.Web.Http.WebHost.dll!System.Web.Http.WebHost.HttpControllerHandler.ProcessRequestAsyncCore(System.Web.HttpContextBase contextBase = {unknown})    C#
     System.Web.Http.WebHost.dll!System.Web.Http.WebHost.HttpControllerHandler.ProcessRequestAsync(System.Web.HttpContext context = {unknown})    C#
     System.Web.dll!<>c__DisplayClass4_0.AnonymousMethod()    C#
     System.Web.dll!System.Web.TaskAsyncHelper.BeginTask(System.Func<System.Threading.Tasks.Task> taskFunc = {unknown}, System.AsyncCallback callback = {unknown}, object state = {unknown})    C#
     System.Web.dll!System.Web.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context = {unknown}, System.AsyncCallback cb = {unknown}, object extraData = {unknown})    C#
     System.Web.dll!CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    C#
     System.Web.dll!System.Web.HttpApplication.ExecuteStep(IExecutionStep step = {unknown}, ref bool completedSynchronously = {unknown})    C#
     System.Web.dll!PipelineStepManager.ResumeSteps(System.Exception error = {unknown})    C#
     System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context = {unknown}, System.AsyncCallback cb = {unknown})    C#




SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 11, 2016 12:29 PM UTC

Hi Brian, 

In case, no sorting request has been initiated at the Grid end, the OrderBy query options will not be available at the server-end. Therefore, we can handle this by checking some conditions as shown below. And there is no need to initiate the sorting from the client-end to handle these kind of typo. Since you can handle them at the server end by checking whether the OrderBy is null or not. 

 


So we would like to handle the OrderBy or any other query using above code example. If you are still facing any issue, please share the information requested in our last update. If you could have provide the code example of your code behind/api controller, which would be helpful to inspect the issue and provide the solution as soon as possible. 

Regards, 
Seeni Sakthi Kumar S. 



RB R Brian Lindahl November 11, 2016 10:29 PM UTC

I have very similar code in my data controller. I have added an "else" on the "if (opts.OrderBy == null)" to provide a valid OrderBy clause in the query. Without it, an EntittyFramework dbSet will not accept the "opts.Skip" clause. My question is, is there a way in the grid declaration to specify the default sort order for the grid? I have .allowSorting set, but until I click on a column header, it won't send an orderBy clause.


RU Ragavee U S Syncfusion Team November 14, 2016 06:38 AM UTC

Hi Brian, 

Yes. We can perform initial sorting in grid using the SortedColumns property of the Grid. Please refer to the below online documentation link where we have discussed on the initial sorting concept. 



Regards, 
Ragavee U S. 


Loader.
Up arrow icon