/// <summary>
        ///     Extensao do GridBound para criação do checkbox para visualização de campos true/false
        /// </summary>
        /// <typeparam name="TModel">Tipo utilizado pela coluna</typeparam>
        /// <param name="builder">Objeto extendido</param>
        /// <param name="id">Nome do objeto de checkbox</param>
        /// <returns>GridBound de retorno</returns>
        public static GridBoundColumnBuilder <TModel> VisualizarCheckBox <TModel>(this GridBoundColumnBuilder <TModel> builder, string id, string campoAtivo = "IsAtivo") where TModel : class, new()
        {
            var template =
                "<input name='IsAtivo#= " + id + "#>' id='IsAtivo#= " + id + "#' type='checkbox' #= " + campoAtivo + " ? checked='checked' : '' # onclick='return false;' />";

            return(builder.HtmlAttributes(new { style = "text-align: center;" }).ClientTemplate(template));;
        }
Example #2
0
 public static GridBoundColumnBuilder <T> Centered <T>(this GridBoundColumnBuilder <T> columnBuilder) where T : class
 {
     return(columnBuilder.HtmlAttributes(new { align = "center" })
            .HeaderHtmlAttributes(new { style = "text-align:center;" }));
 }
 public static GridBoundColumnBuilder <TModel> AlignRight <TModel>(this GridBoundColumnBuilder <TModel> builder, string formatString = null) where TModel : class
 {
     return(builder.HtmlAttributes(new { @class = "alignRight" }));
 }
        public void HtmlAttributes_sets_the_html_attributes_of_the_column()
        {
            builder.HtmlAttributes(new { @class = "test" });

            Assert.Equal("test", column.HtmlAttributes["class"]);
        }
Example #5
0
        public static GridBuilder <T> VnrGrid <T>(this HtmlHelper helper,
                                                  GridBuilderInfo builderInfo) where T : class
        {
            #region PageableBuilder

            Action <PageableBuilder> pageable = new Action <PageableBuilder>(d => d.PageSizes(builderInfo.ShowPageSize).Input(builderInfo.ShowInputPageNumber).PreviousNext(builderInfo.ShowNextPrevious).Numeric(builderInfo.ShowPageNumber).Refresh(true).ButtonCount(5));
            builderInfo.ObjectType = builderInfo.ObjectType != null ? builderInfo.ObjectType : typeof(T);

            Action <GridSelectionSettingsBuilder> selection = new Action <GridSelectionSettingsBuilder>(d =>
                                                                                                        d.Mode(builderInfo.SelectionMode).Type(builderInfo.SelectionType));

            Action <GridToolBarCommandFactory <T> > toolBar = new Action <GridToolBarCommandFactory <T> >(d =>
            {
                if (builderInfo.ShowCreateButton && !string.IsNullOrWhiteSpace(builderInfo.CreateActionUrl))
                {
                    d.Create().Text(DefaultConstants.Create.TranslateString());
                }
                if (builderInfo.ShowSaveButton && !string.IsNullOrWhiteSpace(builderInfo.EditActionUrl))
                {
                    d.Save().Text(DefaultConstants.Create.TranslateString());
                }
                if (builderInfo.ShowCustomCreate && !string.IsNullOrWhiteSpace(builderInfo.EventCustomAdd))
                {
                    d.Custom().Text(DefaultConstants.Create.TranslateString()).Url("#").HtmlAttributes(new { onclick = builderInfo.EventCustomAdd });
                }

                if (builderInfo.ShowCustomSaveChanges && !string.IsNullOrWhiteSpace(builderInfo.EventCustomSaveChanges) && !string.IsNullOrWhiteSpace(builderInfo.EventCustomCancelChanges))
                {
                    d.Custom().Text(builderInfo.CustomSaveChangesText).Url("#").HtmlAttributes(new { onclick = builderInfo.EventCustomSaveChanges });
                    d.Custom().Text(builderInfo.CustomCancelChangesText).Url("#").HtmlAttributes(new { onclick = builderInfo.EventCustomCancelChanges });
                }
            });

            Action <GridEditingSettingsBuilder <T> > editing = new Action <GridEditingSettingsBuilder <T> >(d =>
            {
                d.Mode(builderInfo.EditMode);
                if (!string.IsNullOrWhiteSpace(builderInfo.EditTemplate))
                {
                    d.TemplateName(builderInfo.EditTemplate);
                }
            });

            Action <GridEventBuilder> events = new Action <GridEventBuilder>(d =>
            {
                //if (builderInfo.ForeignKey.Count>0)
                //    d.Save("onSave");
                if (!string.IsNullOrWhiteSpace(builderInfo.SelectionHandler))
                {
                    d.Change(builderInfo.SelectionHandler);
                }
                if (!string.IsNullOrWhiteSpace(builderInfo.EventSaveChanges))
                {
                    d.SaveChanges(builderInfo.EventSaveChanges);
                }
                if (!string.IsNullOrWhiteSpace(builderInfo.EventDataBound))
                {
                    d.DataBound(builderInfo.EventDataBound);
                }
                else
                {
                    //[Tung.Ly 20140908 ] : dùng mặc định (viết ở _layout.cshtml ở main)
                    d.DataBound("dataBound");
                }
                if (!string.IsNullOrWhiteSpace(builderInfo.EvenEdit))
                {
                    d.Edit(builderInfo.EvenEdit);
                }
            });

            #endregion

            #region GridColumnFactory


            var lockedCol = false;
            if (builderInfo.LockedFields != null && builderInfo.LockedFields.Any())
            {
                lockedCol = true;
            }

            Action <GridColumnFactory <T> > columns = new Action <GridColumnFactory <T> >(column =>
            {
                if (builderInfo.ValueFields != null)
                {
                    column.AutoGenerate(builderInfo.ValueFields.Count() == 0);

                    if (builderInfo.ShowCheckbox)
                    {
                        if (builderInfo.ShowCheckAll)
                        {
                            column.Bound("").Title("").HeaderTemplate("<input type='checkbox' id='mastercheckbox' /><div style='border: solid 1px #c5c5c5; margin-top: -3px; border-radius: initial; display: none; width: 60px; position: fixed; z-index: 99; background-color: #F8F8F8; ' class='hrm_treeview' id='MultipleSelectForPage'> <label><input type='radio' value='0' name='selectOnePageOrAllPage' checked /> Page</label><br /> <label><input value='1' type='radio' name='selectOnePageOrAllPage' /> All</label></div>").ClientTemplate("<input type='checkbox' value='#=ID#' class='checkboxGroups'/>").Width(25).Locked(lockedCol).Sortable(false);
                        }
                        else
                        {
                            column.Bound("").Title("").ClientTemplate("<input type='checkbox' value='#=ID#' class='checkboxGroups'/>").Width(25).Locked(lockedCol).Sortable(false);
                        }
                    }
                    if (builderInfo.ShowEditIcon)
                    {
                        column.Bound("").Title("").ClientTemplate("<img src='/Content/images/icons/edit-file-icon.png' title='Edit' alt='Edit' name='gridEditImgButton' class='gridEditImgButton' />").Width(30).Locked(lockedCol).Sortable(false);
                    }
                    if (builderInfo.ShowCommand)
                    {
                        column.Command(d =>
                        {
                            if (builderInfo.ShowEditButton && !string.IsNullOrWhiteSpace(builderInfo.EditActionUrl))
                            {
                                d.Edit()
                                .Text(string.Empty)
                                .UpdateText(DefaultConstants.Save.TranslateString())
                                .CancelText(string.Empty);
                                // d.Edit().HtmlAttributes(new{@class="abdd"})
                            }

                            if (builderInfo.ShowDeleteButton &&
                                !string.IsNullOrWhiteSpace(builderInfo.DeleteActionUrl))
                            {
                                d.Destroy().Text(DefaultConstants.Delete.TranslateString());
                            }
                            if (builderInfo.ShowCustomEdit && !string.IsNullOrWhiteSpace(builderInfo.EventCustomEdit))
                            {
                                d.Custom(builderInfo.EditText).HtmlAttributes(new { @class = "k-icon k-i-pencil" }).Click(builderInfo.EventCustomEdit);
                            }
                        }).Width(170);
                    }


                    foreach (var valueField in builderInfo.ValueFields)
                    {
                        var locked = false;
                        if (builderInfo.LockedFields != null)
                        {
                            if (builderInfo.LockedFields.Contains(valueField))
                            {
                                locked = true;
                            }
                        }
                        GridBoundColumnBuilder <T> bound = null;

                        string displayField = string.Empty, formatField = string.Empty, hyperlinkField = string.Empty, template = string.Empty;
                        bool filterable     = false;
                        Type fieldValueType = GetFieldValueType(builderInfo, valueField);
                        if (fieldValueType != null)
                        {
                            //Biến phân biệt đã add foreignKey hay chưa
                            bool _tmp = false;

                            foreach (var foreignKey in builderInfo.ForeignKey)
                            {
                                if (foreignKey.Key.ToString() == valueField)
                                {
                                    if (foreignKey.Key != null && foreignKey.Value != null && foreignKey.Value.Count() > 3)
                                    {
                                        IList lstFk = (IList)foreignKey.Value[2];
                                        if (lstFk != null)
                                        {
                                            if (foreignKey.Value[4].ToString() != string.Empty)
                                            {
                                                bound = column.ForeignKey(foreignKey.Key.ToString(), lstFk, foreignKey.Value[0].ToString(), foreignKey.Value[1].ToString()).Width(150).Title(foreignKey.Value[3].ToString().TranslateString()).EditorTemplateName(foreignKey.Value[4].ToString());
                                            }
                                            else
                                            {
                                                bound = column.ForeignKey(foreignKey.Key.ToString(), lstFk, foreignKey.Value[0].ToString(), foreignKey.Value[1].ToString()).Width(150).Title(foreignKey.Value[3].ToString().TranslateString());
                                            }
                                        }
                                        _tmp = true;
                                        break;
                                    }
                                }
                            }
                            if (!_tmp)
                            {
                                bound = column.Bound(fieldValueType, valueField).Locked(locked);
                                if (fieldValueType.IsBoolean())
                                {
                                    bound.ClientTemplate("<input type='checkbox' disabled='" + builderInfo.DisabledCheckbox + "' #= " + valueField + " ? 'checked=checked':'' # class='chkbx' />");
                                }
                                else if (fieldValueType.IsDateTime() || fieldValueType.IsFloat() || fieldValueType.IsNumeric() || fieldValueType.IsDouble() || fieldValueType.IsInteger() || fieldValueType.IsDecimal())
                                {
                                    bound.HtmlAttributes(new { style = "text-align:right" });
                                }
                                if (fieldValueType.IsDouble())
                                {
                                    bound.EditorTemplateName("Number");
                                }
                                if (fieldValueType.IsFloat())
                                {
                                    bound.EditorTemplateName("Percent");
                                }
                            }
                        }
                        else
                        {
                            bound = column.Bound(valueField).Locked(locked);
                        }

                        if (builderInfo.HasDisplayFields())
                        {
                            displayField = builderInfo.DisplayFields.Where(d => d.Key
                                                                           == valueField).Select(d => d.Value).FirstOrDefault();
                        }

                        if (string.IsNullOrWhiteSpace(displayField))
                        {
                            displayField = valueField;
                        }
                        bound.Title(displayField.TranslateString());
                        #region Format Column
                        if (builderInfo.HasFormatFields())
                        {
                            formatField = builderInfo.FormatFields.Where(d => d.Key
                                                                         == valueField).Select(d => d.Value).FirstOrDefault();
                        }

                        if (builderInfo.HasHyperlink())
                        {
                            hyperlinkField = builderInfo.HyperlinkFields.Where(d => d.Key
                                                                               == valueField).Select(d => d.Value).FirstOrDefault();
                        }
                        if (builderInfo.HasFilterable())
                        {
                            filterable = builderInfo.Filterable.Where(d => d.Key
                                                                      == valueField).Select(d => d.Value).FirstOrDefault();
                        }

                        //bound.Filterable(filterable);
                        bound.Filterable(filterable).Filterable(_filterable => _filterable
                                                                .Extra(false)
                                                                .Operators(ops =>
                                                                           ops.ForString(str => str.Clear()
                                                                                         .Contains("Contains")
                                                                                         .StartsWith("Starts with")
                                                                                         .EndsWith("Ends with")
                                                                                         .IsEqualTo("Is equal to"))
                                                                           ));

                        if (builderInfo.HasTemplate())
                        {
                            template = builderInfo.Template.Where(d => d.Key
                                                                  == valueField).Select(d => d.Value).FirstOrDefault();
                        }

                        if (builderInfo.HasSizeFields())
                        {
                            int fieldWidth = builderInfo.SizeFields.Where(d => d.Key
                                                                          == valueField).Select(d => d.Value).FirstOrDefault();

                            if (fieldWidth >= 10)
                            {
                                bound.Width(fieldWidth);
                            }
                        }

                        if (string.IsNullOrWhiteSpace(formatField))
                        {
                            formatField = GetDefaultFormat(fieldValueType);
                        }

                        if (!string.IsNullOrWhiteSpace(hyperlinkField))
                        {
                            var itemHyperlink = hyperlinkField.Split(',');
                            if (itemHyperlink.Count() > 1)
                            {
                                bound.ClientTemplate("<a onClick=\"" + itemHyperlink[0] + "('#=" + itemHyperlink[1] + "#')\">#=" + valueField + "#</a>");
                            }
                            else
                            {
                                bound.ClientTemplate("<a onClick=\"" + hyperlinkField + "('#=ID#')\">#=" + valueField + "#</a>");
                            }
                        }
                        if (builderInfo.SumFields != null && builderInfo.SumFields.Any())
                        {
                            foreach (var field in builderInfo.SumFields)
                            {
                                if (field == valueField)
                                {
                                    var str = "#=sum#";
                                    if (!string.IsNullOrEmpty(builderInfo.FormatSum))
                                    {
                                        str = "#=kendo.toString(sum,'" + builderInfo.FormatSum + "')#";
                                    }
                                    bound.ClientFooterTemplate(str);
                                    break;
                                }
                            }
                        }

                        if (builderInfo.GroupHeaderTemplate != null && builderInfo.GroupFields != null && builderInfo.GroupFields.Any())
                        {
                            var header = builderInfo.GroupHeaderTemplate;
                            foreach (var field in builderInfo.GroupFields)
                            {
                                if (header.ContainsKey(field) && !string.IsNullOrEmpty(header[field].ToString()))
                                {
                                    bound.ClientGroupHeaderTemplate(header[field]);
                                    break;
                                }
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(formatField))
                        {
                            if (!formatField.Contains("{") || !formatField.Contains("}"))
                            {
                                formatField = "{0:" + formatField + "}";
                            }

                            bound.Format(formatField);
                        }

                        if (builderInfo.HiddenFields != null && builderInfo.HiddenFields.Contains(valueField))
                        {
                            bound.Hidden(true);
                        }


                        #endregion
                    }

                    //foreach (var foreignKey in builderInfo.ForeignKey)
                    //{
                    //    if (foreignKey.Key != null && foreignKey.Value != null && foreignKey.Value.Count() > 3)
                    //    {
                    //        IList lstFk = (IList)foreignKey.Value[2];
                    //        if (lstFk != null)
                    //        {
                    //            if (foreignKey.Value[4].ToString() != string.Empty)
                    //            {
                    //                column.ForeignKey(foreignKey.Key.ToString(), lstFk, foreignKey.Value[0].ToString(), foreignKey.Value[1].ToString()).Width(150).Title(foreignKey.Value[3].ToString().TranslateString()).EditorTemplateName(foreignKey.Value[4].ToString());
                    //            }
                    //            else
                    //            {
                    //                column.ForeignKey(foreignKey.Key.ToString(), lstFk, foreignKey.Value[0].ToString(), foreignKey.Value[1].ToString()).Width(150).Title(foreignKey.Value[3].ToString().TranslateString());
                    //            }
                    //        }
                    //    }
                    //}
                    //column.Bound("").Title("").Sortable(false).Filterable(false).CompareByOperator(;
                    column.Bound("").Title("").Sortable(false).Filterable(filterable => filterable
                                                                          .Extra(false)
                                                                          .Operators(ops =>
                                                                                     ops.ForString(str => str.Clear()
                                                                                                   .Contains("Contains")
                                                                                                   .StartsWith("Starts with")
                                                                                                   .EndsWith("Ends with")
                                                                                                   .IsEqualTo("Is equal to"))
                                                                                     ));
                }
            });

            #endregion

            #region DataSourceBuilder
            Action <DataSourceBuilder <T> > dataSource = new Action <DataSourceBuilder <T> >(data =>
            {
                AjaxDataSourceBuilder <T> ajaxDataSource = data.Ajax();
                ajaxDataSource.Events(e => e.Error("ErrorHandler"));
                ajaxDataSource.Batch(builderInfo.Batch);

                int pos = Array.IndexOf(builderInfo.ValueFields, builderInfo.DefaultSortField);
                if (pos > -1)
                {
                    ajaxDataSource.Sort(sort => sort.Add(builderInfo.DefaultSortField).Descending());
                }

                if (!string.IsNullOrWhiteSpace(builderInfo.EventError))
                {
                    ajaxDataSource.Events(e => e.Error(builderInfo.EventError));
                }

                if (builderInfo.GroupFields != null && builderInfo.GroupFields.Count() > 0)
                {
                    foreach (var groupField in builderInfo.GroupFields)
                    {
                        if (!string.IsNullOrWhiteSpace(groupField))
                        {
                            ajaxDataSource.Group(group =>
                            {
                                group.Add(groupField, GetFieldValueType(builderInfo, groupField));
                            });
                        }
                    }
                }

                if (builderInfo.SumFields != null && builderInfo.SumFields.Count() > 0)
                {
                    ajaxDataSource.Aggregates(agg =>
                    {
                        foreach (var sumField in builderInfo.SumFields)
                        {
                            if (!string.IsNullOrWhiteSpace(sumField))
                            {
                                agg.Add(sumField, GetFieldValueType(builderInfo, sumField)).Sum();
                            }
                        }
                    });
                }

                if (builderInfo.PageSize > 0)
                {
                    ajaxDataSource.PageSize(builderInfo.PageSize);
                }
                if (!builderInfo.ServerOperation)
                {
                    ajaxDataSource.ServerOperation(builderInfo.ServerOperation);
                }

                ajaxDataSource.Model(model =>
                {
                    if (!string.IsNullOrWhiteSpace(builderInfo.IdPropertyName))
                    {
                        model.Id(builderInfo.IdPropertyName);
                    }

                    foreach (var valueField in builderInfo.ValueFields)
                    {
                        Type fieldValueType = GetFieldValueType(builderInfo, valueField);
                        bool editable       = true;

                        if (builderInfo.DisableFields != null)
                        {
                            editable = !builderInfo.DisableFields.Contains(valueField);
                        }

                        if (fieldValueType != null)
                        {
                            model.Field(valueField, fieldValueType).Editable(editable);
                        }
                        else
                        {
                            model.Field(valueField, typeof(string)).Editable(editable);
                        }
                    }
                });

                if (!string.IsNullOrWhiteSpace(builderInfo.ReadActionUrl))
                {
                    if (builderInfo.ReadActionUrl.Contains("/"))
                    {
                        if (!string.IsNullOrWhiteSpace(builderInfo.ReadData))
                        {
                            //ajaxDataSource.Read(action => action.Url(builderInfo.ReadActionUrl).Data("OverWriteReadDataOnGrid(" + builderInfo.ReadData + ")"));
                            ajaxDataSource.Read(action => action.Url(builderInfo.ReadActionUrl).Data(builderInfo.ReadData));
                        }
                        else
                        {
                            //Trường hợp ReadActionUrl là một đường dẫn url
                            ajaxDataSource.Read(action => action.Url(builderInfo.ReadActionUrl));
                        }
                    }
                    else
                    {
                        //Trường hợp ReadActionUrl là một action name trong một controller
                        if (builderInfo.ReadParameter != null)
                        {
                            ajaxDataSource.Read(builderInfo.ReadActionUrl, builderInfo.Controller, builderInfo.ReadParameter);
                        }
                        if (!string.IsNullOrWhiteSpace(builderInfo.ReadData))
                        {
                            ajaxDataSource.Read(r => r.Action(builderInfo.ReadActionUrl, builderInfo.Controller).Data(builderInfo.ReadData));
                        }
                        //ajaxDataSource.Read(builderInfo.ReadActionUrl, builderInfo.Controller);
                    }
                }

                if (!string.IsNullOrWhiteSpace(builderInfo.CreateActionUrl))
                {
                    if (builderInfo.CreateActionUrl.Contains("/"))
                    {
                        //Trường hợp ReadActionUrl là một đường dẫn url
                        ajaxDataSource.Create(action => action.Url(builderInfo.CreateActionUrl));
                    }
                    else
                    {
                        //Trường hợp ReadActionUrl là một action name trong một controller
                        ajaxDataSource.Create(builderInfo.CreateActionUrl, builderInfo.Controller);
                    }
                }

                if (!string.IsNullOrWhiteSpace(builderInfo.EditActionUrl))
                {
                    if (builderInfo.EditActionUrl.Contains("/"))
                    {
                        //Trường hợp ReadActionUrl là một đường dẫn url
                        ajaxDataSource.Update(action => action.Url(builderInfo.EditActionUrl));
                    }
                    else
                    {
                        //Trường hợp ReadActionUrl là một action name trong một controller
                        ajaxDataSource.Update(builderInfo.EditActionUrl, builderInfo.Controller);
                    }
                }

                if (!string.IsNullOrWhiteSpace(builderInfo.DeleteActionUrl))
                {
                    if (builderInfo.DeleteActionUrl.Contains("/"))
                    {
                        //Trường hợp ReadActionUrl là một đường dẫn url
                        ajaxDataSource.Destroy(action => action.Url(builderInfo.DeleteActionUrl));
                    }
                    else
                    {
                        //Trường hợp ReadActionUrl là một action name trong một controller
                        ajaxDataSource.Destroy(builderInfo.DeleteActionUrl, builderInfo.Controller);
                    }
                }
            });

            #endregion

            #region GridBuilder

            var gridbuilder = helper.Kendo().Grid <T>()
                              .Name(builderInfo.Name)
                              .Groupable(d => d.Enabled(builderInfo.ShowGroupPanel))
                              .AutoBind(builderInfo.AutoBind)
                              .Resizable(d => d.Columns(true))
                              .Reorderable(d => d.Columns(true))
                              .Sortable(d => d.SortMode(GridSortMode.MultipleColumn))
                              .ToolBar(toolBar)
                              .Selectable(selection)
                              .Pageable(pageable)
                              .Columns(columns)
                              .ColumnMenu()
                              .Filterable()
                              .Editable(editing)
                              .DataSource(dataSource)
                              .Events(events)
                              //.ToolBar(tb =>
                              //{
                              //    tb.Custom().Name("ChangeColumnMode").Text("<img alt='icon' class='k-image' src='../Content/images/icons/submenu/menu/Sys_table_edit.png'>ChangeColumnMode").Url("#").HtmlAttributes(new { onclick = "ClickButtonChangeColum2('" + builderInfo.ObjectType.Name + "')" });
                              //    tb.Custom().Name("update-inventory").Text("Update Inventory").HtmlAttributes(
                              //        new {onclick = "onUpdateInventory()", title = "Update the system inventory from the OMS", @class="k-refresh"});
                              //} )
            ;

            if (!string.IsNullOrEmpty(builderInfo.ClientDetailTemplateId))
            {
                gridbuilder.ClientDetailTemplateId(builderInfo.ClientDetailTemplateId);
            }
            IDictionary <string, object> attributes = new Dictionary <string, object>();
            var strStyle = string.Empty;
            if (builderInfo.GridHeight > 0)
            {
                strStyle += "height:" + builderInfo.GridHeight + "px; ";
            }
            if (builderInfo.GridWidth > 0)
            {
                strStyle += "width:" + builderInfo.GridWidth + "px; ";
            }
            if (!string.IsNullOrEmpty(strStyle))
            {
                attributes.Add("style", strStyle);
            }
            if (attributes.Any())
            {
                gridbuilder.HtmlAttributes(attributes);
            }
            if (builderInfo.ColumnFilterable)
            {
                gridbuilder.Filterable();
            }

            if (builderInfo.ColumnMenu)
            {
                gridbuilder.ColumnMenu();
            }
            if (builderInfo.Scrollable)
            {
                if (builderInfo.ScrollableHeight > 0)
                {
                    gridbuilder.Scrollable(s => s.Height("auto"));
                }
                else
                {
                    gridbuilder.Scrollable();
                }
            }
            if (builderInfo.Navigatable)
            {
                gridbuilder.Navigatable();
            }
            if (builderInfo.ToClientTemplate)
            {
                gridbuilder.ToClientTemplate();
            }
            return(gridbuilder);

            #endregion
        }
 public static GridBoundColumnBuilder <T> RightAlign <T>(this GridBoundColumnBuilder <T> columnBuilder) where T : class
 {
     return(columnBuilder.HtmlAttributes(new { style = "text-align:right;" }).HeaderHtmlAttributes(new { style = "text-align:right;" }));
 }
 public static GridBoundColumnBuilder <T> RoundedImage <T>(this GridBoundColumnBuilder <T> columnBuilder) where T : class
 {
     return(columnBuilder.HtmlAttributes(new { @class = "rounded-image" }));
 }
Example #8
0
        //Created By SK.
        public static GridBuilder <T> BuildGrid <T>(
            this GridBuilder <T> gridbuilder,
            string gridName,
            string ajaxController,
            string action,
            object routedValue,
            string indexID,
            string[] hiddenColumns = null, bool allowInsert = true, bool allowEdit = true, bool allowDelete = true, EnumFeatures feature = EnumFeatures.Exempt) where T : class
        {
            bool isEditable = true;
            bool isVisible  = true;

            allowEdit   &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Edit);
            allowInsert &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Add);
            allowDelete &= (feature == EnumFeatures.Exempt) ? true : AccessControl.IsActionAccessible(HttpContext.Current.User, feature, EnumActions.Delete);

            GridBuilder <T> retVal = gridbuilder.Name(gridName).DataKeys(k => k.Add("ID"))
                                     .Scrollable(sc => sc.Height("*"))
                                     .Resizable(rs => rs.Columns(true))
                                     .EnableCustomBinding(true)
                                     .Pageable(paging => paging.PageSize(ConfigurationHelper.GetsmARTDetailGridPageSize())
                                               .Style(Telerik.Web.Mvc.UI.GridPagerStyles.NextPreviousAndNumeric)
                                               .Total(100))
                                     .DataBinding(bindings => bindings.Ajax()
                                                  .Select(action, ajaxController, routedValue)
                                                  .Insert("_Insert", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) })
                                                  .Update("_Update", ajaxController, new { isNew = (indexID.Equals("0") ? true : false) })
                                                  .Delete("_Delete", ajaxController, new { MasterID = indexID, isNew = (indexID.Equals("0") ? true : false) })
                                                  );


            if (isEditable && isVisible)
            {
                if (allowInsert)
                {
                    retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true))).ToolBar(commands => commands.Insert());
                }
                retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true)));
            }
            else
            {
                retVal.Editable(editing => editing.Enabled(false));
            }

            Type typeT = typeof(T);

            PropertyInfo[] properties = typeT.GetProperties();

            //// Add keys
            //GridDataKeyFactory<T> dataKeys = new GridDataKeyFactory<T>(retVal);
            //foreach (PropertyInfo property in properties)
            //  if (IsAttributePresent<KeyAttribute>(property))
            //    dataKeys.Add(property.Name);

            // Add Columns
            GridColumnFactory <T> columns = new GridColumnFactory <T>(retVal);

            foreach (PropertyInfo property in properties)
            {
                bool IsColumnVisible = !IsAttributePresent <HiddenInputAttribute>(property);
                if (hiddenColumns != null && hiddenColumns.Contains(property.Name))
                {
                    continue;
                }
                GridBoundColumnBuilder <T> gridBoundBuilder = columns.Bound(property.Name).Visible(IsColumnVisible);

                //Set numeric column to right align.
                if (property.PropertyType == typeof(decimal) || property.PropertyType == typeof(double))
                {
                    gridBoundBuilder.HtmlAttributes(new { style = "text-align: right;" }).Format("{0:0.00}");
                }

                if (IsAttributePresent <ClientTemplateHtmlAttribute>(property))
                {
                    gridBoundBuilder.ClientTemplate(property.TemplateHtmlForProperty());
                }
            }


            if (isEditable && isVisible)
            {
                columns.Command(commands => {
                    if (allowEdit)
                    {
                        commands.Edit().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                    }
                    if (allowDelete)
                    {
                        commands.Delete().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                    }
                }
                                );
            }

            return(retVal);
        }
Example #9
0
        public static GridBuilder <T> BuildGrid <T>(
            this GridBuilder <T> gridbuilder,
            string gridName,
            string ajaxController,
            bool useClientTemplateHtml
            ) where T : class
        {
            bool isEditable = true;
            bool isVisible  = true;

            GridBuilder <T> retVal = gridbuilder.Name(gridName).DataKeys(k => k.Add("ID"))
                                     .Scrollable(sc => sc.Height("*"))
                                     .Resizable(rs => rs.Columns(true))
                                     .EnableCustomBinding(true)
                                     .Pageable(paging => paging.PageSize(ConfigurationHelper.GetsmARTDetailGridPageSize())
                                               .Style(Telerik.Web.Mvc.UI.GridPagerStyles.NextPreviousAndNumeric)
                                               .Total(100))
                                     .DataBinding(bindings => bindings.Ajax()
                                                  .Select("_Index", ajaxController)
                                                  .Insert("_Insert", ajaxController)
                                                  .Update("_Update", ajaxController)
                                                  .Delete("_Delete", ajaxController));

            if (isEditable && isVisible)
            {
                retVal.Editable(editing => editing.Enabled(isEditable).Mode(Telerik.Web.Mvc.UI.GridEditMode.PopUp).Window(w => w.Modal(true))).ToolBar(commands => commands.Insert());
            }
            else
            {
                retVal.Editable(editing => editing.Enabled(false));
            }

            Type typeT = typeof(T);

            PropertyInfo[] properties = typeT.GetProperties();

            //// Add keys
            //GridDataKeyFactory<T> dataKeys = new GridDataKeyFactory<T>(retVal);
            //foreach (PropertyInfo property in properties)
            //  if (IsAttributePresent<KeyAttribute>(property))
            //    dataKeys.Add(property.Name);

            // Add Columns

            if (!useClientTemplateHtml)
            {
                GridColumnFactory <T> columns = new GridColumnFactory <T>(retVal);
                foreach (PropertyInfo property in properties)
                {
                    bool IsColumnVisible = !IsAttributePresent <HiddenInputAttribute>(property);
                    GridBoundColumnBuilder <T> gridBoundBuilder = columns.Bound(property.Name).Visible(IsColumnVisible);

                    //Set numeric column to right align.
                    if (property.PropertyType == typeof(decimal) || property.PropertyType == typeof(double))
                    {
                        gridBoundBuilder.HtmlAttributes(new { style = "text-align: right;" }).Format("{0:0.00}");
                    }

                    if (IsAttributePresent <ClientTemplateHtmlAttribute>(property))
                    {
                        gridBoundBuilder.ClientTemplate(property.TemplateHtmlForProperty());
                    }
                }

                if (isEditable && isVisible)
                {
                    columns.Command(commands => {
                        commands.Edit().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                        commands.Delete().ButtonType(Telerik.Web.Mvc.UI.GridButtonType.Image);
                    }
                                    );
                }
            }
            else
            {
                Type type = typeof(T);
                retVal.ClientRowTemplate(type.TemplateHtml()).Columns(columns => columns.AutoGenerate(false));
            }

            return(retVal);
        }