Hi!
We just decided to upgrade our projects from Telerik grid to Kendo, but this has become a major issue for us, since we have a very deep integration. When we want to show a Grid, we use our own ViewHelper class. This class would modify a Telerik Grid to the way we like.
For instance Grids created this way could have a specific DataAnnotation on each of the models property, that specified:
We just decided to upgrade our projects from Telerik grid to Kendo, but this has become a major issue for us, since we have a very deep integration. When we want to show a Grid, we use our own ViewHelper class. This class would modify a Telerik Grid to the way we like.
For instance Grids created this way could have a specific DataAnnotation on each of the models property, that specified:
- Alternative columnname
- If the column is hidden or not
- Specific datetime format
- Wheather or not to summarize this column
- MANY other options
Also, there are many extensions to the Grid itself, like:
- Should the grid have an Export button, for Excel export
- Should the grid have vertical scrollbars
- Should the grid have text areas over each column for filtering.
We hook on most of the Grids events, to run scrips before the ones provided in the ClientEvents setting.
We have hundreds of Grids created this way, and it makes it easy to maintain since all Grids are defined by their model. To do this, we created Grids like this in the View:
And CreateGridFromType would look like this:
With the upgrade to Kendo, everything has changed. How on earth can we get a hold on the Grid in our ViewHelper? We need to preserve the settings made in the view, like the url to the DataSource and additional Columns. It is not good enough to just create a new Grid from scratch. It has to extend the Grid defined in the View. I hope you have some solution to our problem, since this way of creating Grids is crucial for us.
If i have not explained myself good enough, please let me know. Also, i can provide sample files - but i think the code provided explains most.
<%=ViewHelper.CreateGridFromType<
OverviewTopFiveModel
>(this)
.Name("DailyTopFive")
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("AjaxDailyTopFive", "Home"))
.Filterable()
.Sortable()
.ScrollBars(false)
%>
public
static
GridBuilder<TModel> CreateGridFromType<TModel>(ViewPage page) where TModel :
class
{
// create the custom grid
var component = (page.ViewContext.HttpContext.Items[StyleSheetRegistrar.Key]
as
StyleSheetRegistrar) ??
new
StyleSheetRegistrar(
new
WebAssetCollection(WebAssetDefaultSettings.StyleSheetFilesPath), page.ViewContext, DI.Current.Resolve<IWebAssetCollectionResolver>());
var scriptWrapper = DI.Current.Resolve<ScriptWrapperBase>();
var registrar2 = (page.ViewContext.HttpContext.Items[ScriptRegistrar.Key]
as
ScriptRegistrar) ??
new
ScriptRegistrar(
new
WebAssetCollection(WebAssetDefaultSettings.ScriptFilesPath),
new
List<IScriptableComponent>(), page.ViewContext, DI.Current.Resolve<IWebAssetCollectionResolver>(), scriptWrapper);
var test =
new
CustomViewComponentFactory(page.Html, DI.Current.Resolve<IClientSideObjectWriterFactory>(), ComponentBuilderBase<StyleSheetRegistrar, StyleSheetRegistrarBuilder>.Create(component), ComponentBuilderBase<ScriptRegistrar, ScriptRegistrarBuilder>.Create(registrar2));
var cGrid = test.Grid<TModel>();
var grid =
new
GridBuilder<TModel>(cGrid);
// create the columns
grid.Columns(CreateGridColumnsFromType(grid));
// hook internal events
grid.ClientEvents(e => e.OnLoad(
"onInternalGridLoad"
));
grid.ClientEvents(e => e.OnDataBinding(
"onInternalGridDataBinding"
));
grid.ClientEvents(e => e.OnDataBound(
"onInternalGridDataBound"
));
grid.ClientEvents(e => e.OnDetailViewExpand(
"onInternalGridDetailViewExpand"
));
grid.ClientEvents(e => e.OnDetailViewCollapse(
"onInternalGridDetailViewCollapse"
));
grid.ClientEvents(e => e.OnRowDataBound(
"onInternalRowDataBound"
));
grid.ClientEvents(e => e.OnCommand(
"onInternalGridCommand"
));
return
grid;
}
With the upgrade to Kendo, everything has changed. How on earth can we get a hold on the Grid in our ViewHelper? We need to preserve the settings made in the view, like the url to the DataSource and additional Columns. It is not good enough to just create a new Grid from scratch. It has to extend the Grid defined in the View. I hope you have some solution to our problem, since this way of creating Grids is crucial for us.
If i have not explained myself good enough, please let me know. Also, i can provide sample files - but i think the code provided explains most.