private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata) { JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName); TimestampAttribute timeStampAttribute = null; JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute = null; JqGridColumnSortableAttribute jqGridColumnSortableAttribute = null; JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute = null; JqGridColumnSummaryAttribute jqGridColumnSummaryAttribute = null; foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true)) { timeStampAttribute = (customAttribute as TimestampAttribute) ?? timeStampAttribute; jqGridColumnLayoutAttribute = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute; jqGridColumnSortableAttribute = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute; jqGridColumnFormatterAttribute = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute; jqGridColumnSummaryAttribute = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute; } if (timeStampAttribute != null) { } else { columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute); columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute); columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute); } return(columnModel); }
private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata, IUrlHelper urlHelper) { JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName); TimestampAttribute timeStampAttribute = null; RangeAttribute rangeAttribute = null; RequiredAttribute requiredAttribute = null; JqGridColumnLayoutAttribute jqGridColumnLayoutAttribute = null; JqGridColumnSortableAttribute jqGridColumnSortableAttribute = null; JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute = null; JqGridColumnSearchableAttribute jqGridColumnSearchableAttribute = null; JqGridColumnEditableAttribute jqGridColumnEditableAttribute = null; JqGridColumnSummaryAttribute jqGridColumnSummaryAttribute = null; JqGridColumnMappingAttribute jqGridColumnMappingAttribute = null; foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true)) { timeStampAttribute = (customAttribute as TimestampAttribute) ?? timeStampAttribute; rangeAttribute = (customAttribute as RangeAttribute) ?? rangeAttribute; requiredAttribute = (customAttribute as RequiredAttribute) ?? requiredAttribute; jqGridColumnLayoutAttribute = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute; jqGridColumnSortableAttribute = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute; jqGridColumnFormatterAttribute = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute; jqGridColumnSearchableAttribute = (customAttribute as JqGridColumnSearchableAttribute) ?? jqGridColumnSearchableAttribute; jqGridColumnEditableAttribute = (customAttribute as JqGridColumnEditableAttribute) ?? jqGridColumnEditableAttribute; jqGridColumnSummaryAttribute = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute; jqGridColumnMappingAttribute = (customAttribute as JqGridColumnMappingAttribute) ?? jqGridColumnMappingAttribute; } if (timeStampAttribute != null) { columnModel.Editable = true; columnModel.Hidden = true; } else { columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute); columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute); columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSearchOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnSearchableAttribute, rangeAttribute); columnModel = SetEditOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnEditableAttribute, rangeAttribute, requiredAttribute); columnModel = SetDatePickerDateFormatFromFormatter(columnModel, jqGridColumnFormatterAttribute); columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute); columnModel = SetMappingOptions(columnModel, jqGridColumnMappingAttribute); } return(columnModel); }
private static JqGridColumnModel SetDatePickerDateFormatFromFormatter(JqGridColumnModel columnModel, JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute) { bool setSearchOptionsDatePickerDateFormat = columnModel.Searchable && (columnModel.SearchType == JqGridColumnSearchTypes.JQueryUIDatepicker) && (columnModel.SearchOptions.DatePickerDateFormat == JqGridOptionsDefaults.ColumnModel.JQueryUIWidgets.DatepickerDateFormat); bool setEditOptionsDatePickerDateFormat = false; if (setSearchOptionsDatePickerDateFormat || setEditOptionsDatePickerDateFormat) { if ((jqGridColumnFormatterAttribute != null) && (jqGridColumnFormatterAttribute.Formatter == JqGridPredefinedFormatters.Date) && (jqGridColumnFormatterAttribute.OutputFormat != JqGridOptionsDefaults.ColumnModel.Formatter.OutputFormat) && (jqGridColumnFormatterAttribute.OutputFormat.IndexOfAny(_invalidDateFormatTokens) == -1)) { string datePickerDateFormat = Regex.Replace(jqGridColumnFormatterAttribute.OutputFormat, _ignoredDateFormatTokensRegexExpression, String.Empty); datePickerDateFormat = _dateFormatTokensRegex.Replace(datePickerDateFormat, match => { return(_dateFormatTokensReplecements[match.Value]); }); if (setSearchOptionsDatePickerDateFormat) { columnModel.SearchOptions.DatePickerDateFormat = datePickerDateFormat; } if (setEditOptionsDatePickerDateFormat) { } } } return(columnModel); }
private static JqGridColumnModel SetFormatterOptions(JqGridColumnModel columnModel, JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute) { if (jqGridColumnFormatterAttribute != null) { columnModel.Formatter = jqGridColumnFormatterAttribute.Formatter; columnModel.FormatterOptions = jqGridColumnFormatterAttribute.FormatterOptions; columnModel.UnFormatter = jqGridColumnFormatterAttribute.UnFormatter; } return(columnModel); }
private string JQueryUIDatepickerDataInitRenderer(JqGridCompatibilityModes compatibilityMode, string gridSelector, ModelMetadata propertyMetadata) { StringBuilder dataInitBuilder = new StringBuilder(80); dataInitBuilder.Append("function(element) { setTimeout(function() { $(element).datepicker({ "); if (!String.IsNullOrEmpty(AppendText)) { dataInitBuilder.AppendFormat("appendText: '{0}', ", AppendText); } if (AutoSize) { dataInitBuilder.Append("autoSize: true, "); } if (ChangeMonth) { dataInitBuilder.Append("changeMonth: true, "); } if (ChangeYear) { dataInitBuilder.Append("changeYear: true, "); } if (!ConstrainInput) { dataInitBuilder.Append("constrainInput: true, "); } if (DatePickerDateFormat == JQueryUIWidgetsDefaults.DatepickerDateFormat) { IEnumerable <object> customAttributes = propertyMetadata.ContainerType.GetProperty(propertyMetadata.PropertyName).GetCustomAttributes(true).AsEnumerable(); JqGridColumnFormatterAttribute formatterAttribute = customAttributes.OfType <JqGridColumnFormatterAttribute>().FirstOrDefault(); if (formatterAttribute != null && formatterAttribute.Formatter == JqGridColumnPredefinedFormatters.Date && formatterAttribute.OutputFormat != JqGridOptionsDefaults.FormatterOutputFormat && formatterAttribute.OutputFormat.IndexOfAny(_invalidDateFormatTokens) == -1) { DatePickerDateFormat = Regex.Replace(formatterAttribute.OutputFormat, _ignoredDateFormatTokensRegexExpression, String.Empty); DatePickerDateFormat = _dateFormatTokensRegex.Replace(DatePickerDateFormat, match => { return(_dateFormatTokensReplecements[match.Value]); }); } } dataInitBuilder.AppendFormat("dateFormat: '{0}', ", DatePickerDateFormat); dataInitBuilder.AppendFormat(_jqueryUIDatepickerDaysNamesLocalizationOptions[compatibilityMode], gridSelector); if (FirstDay != 0) { dataInitBuilder.AppendFormat("firstDay: {0}, ", FirstDay); } if (GotoCurrent) { dataInitBuilder.Append("gotoCurrent: true, "); } if (!String.IsNullOrEmpty(MaxDate)) { dataInitBuilder.AppendFormat("maxDate: '{0}', ", MaxDate); } if (!String.IsNullOrEmpty(MinDate)) { dataInitBuilder.AppendFormat("minDate: '{0}', ", MinDate); } dataInitBuilder.AppendFormat(_jqueryUIDatepickerMonthsNamesLocalizationOptions[compatibilityMode], gridSelector); if (NumberOfMonths != 1) { dataInitBuilder.AppendFormat("numberOfMonths: {0}, ", NumberOfMonths); } if (SelectOtherMonths) { dataInitBuilder.Append("selectOtherMonths: true, "); } if (ShortYearCutoff != JQueryUIWidgetsDefaults.DatepickerShortYearCutoff) { dataInitBuilder.AppendFormat("shortYearCutoff: '{0}', ", ShortYearCutoff); } if (ShowCurrentAtPos != 0) { dataInitBuilder.AppendFormat("showCurrentAtPos: {0}, ", ShowCurrentAtPos); } if (ShowMonthAfterYear) { dataInitBuilder.Append("showMonthAfterYear: true, "); } if (ShowOtherMonths) { dataInitBuilder.Append("showOtherMonths: true, "); } if (ShowWeek) { dataInitBuilder.Append("showWeek: true, "); } if (StepMonths != 1) { dataInitBuilder.AppendFormat("stepMonths: {0}, ", StepMonths); } if (YearRange != JQueryUIWidgetsDefaults.DatepickerYearRange) { dataInitBuilder.AppendFormat("yearRange: '{0}', ", YearRange); } if (!String.IsNullOrEmpty(YearSuffix)) { dataInitBuilder.AppendFormat("yearSuffix: '{0}', ", YearSuffix); } dataInitBuilder.Remove(dataInitBuilder.Length - 2, 2); dataInitBuilder.Append(" }); }, 0); }"); return(dataInitBuilder.ToString()); }