or
[Display(Name = "Days Late"), UIHint("_DaysToDate"), ReadOnly(true)]
public int? DaysLate
{
get; set;
}private static GridBuilder<dynamic> CreateDynamicGrid<TBaseViewModelType>(this HtmlHelper helper, string gridName, string provisioningControllerName, string formActionName = "Edit", bool checkboxRowSelect = false)
{
var type = typeof(TBaseViewModelType);
var modelProperties = type.GetProperties().Where(p => p.IsScaffoldable()).ToList();
var identityProperty = type.GetProperty("Id");
var idFieldName = string.Empty;
if (identityProperty != null)
{
idFieldName = identityProperty.Name;
}
return helper.Kendo().Grid<dynamic>()
.Name(gridName)
.Columns(columns => {
columns.Template(t => t).ClientTemplate("<input class='select-row' type='checkbox' />").HeaderTemplate(t => "<input class='select-all-rows' type='checkbox' />").Width(40).Visible(checkboxRowSelect);
columns.Template(t => t).ClientTemplate(helper.ActionLink(VisionWebResources.Action_More, formActionName, provisioningControllerName, new { id = string.Format("#= {0} #", idFieldName) }, null).ToHtmlString()).Visible(identityProperty != null).Width("4em");
modelProperties.ForEach(p => columns.Bound(p.GetPrevailingType(), p.Name).Format(p.GetFormatString()).HtmlAttributes(p.GetHtmlAttributes()).Width(InitialColumnWidth)); })
.DataSource(ds => ds.Ajax()
.PageSize(15) .Read(r => r.Action("Read", provisioningControllerName))
.Model(model =>
{
model.Id("Id");
foreach (var property in modelProperties) {model.Field(property.Name, property.GetPrevailingType));
}
})
)
.Editable(ed => ed.Enabled(false))
.Events(events => events.DataBound("function() { " +
"if (typeof (gridDataBound) === 'function') { gridDataBound(); }" + "}").Change("function() { " +
"if (typeof (gridFocusedRowChanged) === 'function') { gridFocusedRowChanged(); }" +
"}"))
.Filterable() .HtmlAttributes(new { @class = "grid" })
.Navigatable()
.Pageable(pages =>
{
pages.PageSizes(new[] { 15, 25, 40 });
pages.Refresh(true); //Provides a button to refresh the current grid page
}) .Resizable(resize => resize.Columns(true))
.Scrollable(scrollable => scrollable.Height(425))
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Sortable(sortable => sortable.AllowUnsort(false));
}
//define the cells and rowsvar gridCells = $("td[role='gridcell']"); var gridRows = $("tr[role='row']"); //figure out if we should hide the first and/or last row //class will be null if it's normal, otherwise 'k-other-month' if (gridCells[6].getAttribute("class") != null) { $(gridRows[0]).css("display", "none"); } if (gridCells[35].getAttribute("class") != null) { $(gridRows[5]).css("display", "none"); }<div id="grid"></div><script id="detail-template" type="text/kendo-ui-template"> <div> <p>#: FirstName # #: LastName #'s age is #: Age #</p> </div></script><script type="text/javascript"> $(document).ready(function(){ $("#grid").kendoGrid({ sortable: true, editable: "incell", toolbar: ["create"], columns:[ { field: "FirstName", title: "First Name" }, { field: "LastName", title: "Last Name" }], dataSource: { schema: { model: { id: "Id", fields: { FirstName: { type: "string" }, LastName: { type: "string" }, Age: { //data type of the field {Number|String|Boolean} default is String type: "number", // used when new model is created defaultValue: 1 } } } }, data: [ { Id: 1, FirstName: "Joe", LastName: "Smith", Age: 30 }, { Id: 2, FirstName: "Jane", LastName: "Smith", Age: 20 }] }, detailTemplate: kendo.template($("#detail-template").html()), dataBound: function () { this.expandRow(this.tbody.find("tr.k-master-row").first()); }, }); });</script>
$("#mainGrid").kendoGrid({ dataSource: dataSource, pageable: false, sortable: true, scrollable: true, editable: true, autoBind: false, columnMenu: true, // Cria o menu de exibição de colunas height: getGridHeight(), toolbar: [/* hide for brevity */], columns: [/* hide for brevity */], dataBound: function() { /* hide for brevity. */}, edit: function() { /* hide for brevity. */}});