Hi
I have a Telerik grid that I need to be filled dynamicly.
I have a menu which is also dynamic, each item of the menu represented by a unique number, according to this number I know which SQL query to run and fill the grid accordingly.
The grid should have the options for: Insert, Update, Delete.
The grid should also have the option of filtering.
I need to change the columns headers as well at runtime while filling the grid.
What is the best way to implement those needs?
Thanks,
Eliran
7 Answers, 1 is accepted
The RadGrid control can generate its columns based on the available data. You can use that feature and have the grid use autogenerated columns.
As for the Update/Insert/Delete functionality. The grid supports automatic data source operations when it is bound to a declarative DataSource control. Check out the following article that describes the behavior in more detail:
In case you need more advanced features you can also define the RadGrid structure manually. In order to change the structure of the grid dynamically you would need to create it in the code-behind using the Page_Init event. The article below outlines the approach you can use.
Regards,
Viktor Tachev
Telerik by Progress
Thanks Viktor
All problems have been solved when I change the Grid initialization from the Page_Load event to Page_Init.
Eliran
HI,
we have a dynamic datasource to bind to our grid.
during runtime we get then an Iqueryable<xxx> - which we want to bind to a grid.
are there any examples on handling dynamic datasources?
here is my code which i currently have:
@(Html.Kendo().Grid<PartnerViewModel>()
.Name("clientgrid")
.HtmlAttributes(new { style = "height: 500px;" })
.Columns(columns =>
{
columns.Template(c => @Html.ActionLink("Details", "Details", new { id = c.PartnerId, }));
columns.Template(c => @Html.ActionLink("Edit", "Edit", new { id = c.PartnerId, }));
columns.AutoGenerate(true);
})
.Resizable(resize => resize.Columns(true))
.Sortable()
.Groupable()
.Filterable()
.Reorderable(d => d.Columns(true))
.Scrollable(scrollable => scrollable.Virtual(false))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new List<object> { 50, 100, 200, 500, 1000 }).Refresh(true)
.ButtonCount(8))
.DataSource(dataSource => dataSource
.Ajax()
//.Batch(true)
//.ServerOperation(true)
//.Model(model => model.Id(p => p.PartnerId))
.Read(read => read.Action("partners_read", "Home"))
.PageSize(200))
)
this: http://www.telerik.com/support/code-library/binding-to-a-collection-of-dynamic-objects
does not work for me - but is what i need.
i get an exception on "Html.Kendo().Grid(Model)"
Beim Serialisieren eines Objekts vom Typ "System.Reflection.RuntimeModule" wurde ein Zirkelverweis erkannt.
stack
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1440
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +127
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1273
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +127
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1273
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +481
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1318
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +127
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1273
System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +195
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +29
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +64
Kendo.Mvc.Infrastructure.DefaultJavaScriptSerializer.Kendo.Mvc.Infrastructure.IJavaScriptSerializer.Serialize(Object ) +7
Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +504
Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +385
Kendo.Mvc.Infrastructure.JavaScriptInitializer.Serialize(IDictionary`2 object) +385
Kendo.Mvc.Infrastructure.JavaScriptInitializer.InitializeFor(String selector, String name, IDictionary`2 options) +131
Kendo.Mvc.Infrastructure.JavaScriptInitializer.Initialize(String id, String name, IDictionary`2 options) +62
Kendo.Mvc.UI.Grid`1.WriteInitializationScript(TextWriter writer) +1977
Kendo.Mvc.UI.WidgetBase.WriteHtml(HtmlTextWriter writer) +70
Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +938
Kendo.Mvc.UI.WidgetBase.ToHtmlString() +93
Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString() +22
System.Web.HttpUtility.HtmlEncode(Object value) +39
System.Web.WebPages.WebPageBase.Write(Object value) +75
ASP._Page_Views_Partner_Index_cshtml.Execute() in c:\1_PYT_Code\Archipel\Samos.Web\Samos.Web\Views\Partner\Index.cshtml:25
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
System.Web.Mvc.Async.<>c__DisplayClass2b.<
BeginInvokeAction
>b__1c() +173
System.Web.Mvc.Async.<>c__DisplayClass21.<
BeginInvokeAction
>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<
BeginExecuteCore
>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<
BeginExecute
>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<
BeginProcessRequest
>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765045
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
thanks for any advice
The exception you are seeing is a general exception and it would be hard to pinpoint its exact cause without further investigation.
Would you open a support ticket and send a runnable sample where the exception you are seeing is replicated? I would appreciate it if you can modify this example in a way that the error is replicated and send it to us. This would enable us to debug the code and look for what is causing the behavior.
Regards,
Viktor Tachev
Telerik by Progress
Hi Viktor,
the examples on GitHub wont work, since its build up on an old version (MVC 2).
i will check if we can remove these references.
we are using Telerik Data Access component to generate the models and viewmodels dynamicly.
thanks & best regards
M