Ejemplo n.º 1
0
        public static string RemoveQuotesForJavaScriptMethods(string input, JQGrid grid)
        {
            string text = input;

            foreach (JQGridColumn jQGridColumn in grid.Columns)
            {
                if (jQGridColumn.Formatter != null && jQGridColumn.Formatter.Count > 0 && jQGridColumn.Formatter[0] != null)
                {
                    JQGridColumnFormatter jQGridColumnFormatter = jQGridColumn.Formatter[0];
                    if (jQGridColumnFormatter is CustomFormatter)
                    {
                        CustomFormatter customFormatter = (CustomFormatter)jQGridColumnFormatter;
                        string          oldValue        = string.Format("\"formatter\":\"{0}\"", customFormatter.FormatFunction);
                        string          newValue        = string.Format("\"formatter\":{0}", customFormatter.FormatFunction);
                        text     = text.Replace(oldValue, newValue);
                        oldValue = string.Format("\"unformat\":\"{0}\"", customFormatter.UnFormatFunction);
                        newValue = string.Format("\"unformat\":{0}", customFormatter.UnFormatFunction);
                        text     = text.Replace(oldValue, newValue);
                    }
                }
                foreach (JQGridEditClientSideValidator jQGridEditClientSideValidator in jQGridColumn.EditClientSideValidators)
                {
                    if (jQGridEditClientSideValidator is CustomValidator)
                    {
                        CustomValidator customValidator = (CustomValidator)jQGridEditClientSideValidator;
                        string          oldValue2       = string.Format("\"custom_func\":\"{0}\"", customValidator.ValidationFunction);
                        string          newValue2       = string.Format("\"custom_func\":{0}", customValidator.ValidationFunction);
                        text = text.Replace(oldValue2, newValue2);
                    }
                }
                if (jQGridColumn.EditType == EditType.Custom)
                {
                    string oldValue3 = string.Format("\"custom_element\":\"{0}\"", jQGridColumn.EditTypeCustomCreateElement);
                    string newValue3 = string.Format("\"custom_element\":{0}", jQGridColumn.EditTypeCustomCreateElement);
                    text      = text.Replace(oldValue3, newValue3);
                    oldValue3 = string.Format("\"custom_value\":\"{0}\"", jQGridColumn.EditTypeCustomGetValue);
                    newValue3 = string.Format("\"custom_value\":{0}", jQGridColumn.EditTypeCustomGetValue);
                    text      = text.Replace(oldValue3, newValue3);
                }
                if ((jQGridColumn.Editable && jQGridColumn.EditType == EditType.DatePicker) || jQGridColumn.EditType == EditType.AutoComplete)
                {
                    string attachEditorsFunction = GridUtil.GetAttachEditorsFunction(grid, jQGridColumn.EditType.ToString().ToLower(), jQGridColumn.EditorControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachEditControlsScript",
                        jQGridColumn.DataField,
                        '"'
                    }), attachEditorsFunction);
                    text = text.Replace('"' + "dataInit" + '"', "dataInit");
                }
                if ((jQGridColumn.Searchable && jQGridColumn.SearchType == SearchType.DatePicker) || jQGridColumn.SearchType == SearchType.AutoComplete)
                {
                    string attachEditorsFunction2 = GridUtil.GetAttachEditorsFunction(grid, jQGridColumn.SearchType.ToString().ToLower(), jQGridColumn.SearchControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachSearchControlsScript",
                        jQGridColumn.DataField,
                        '"'
                    }), attachEditorsFunction2);
                    text = text.Replace('"' + "dataInit" + '"', "dataInit");
                }
            }
            return(text);
        }
Ejemplo n.º 2
0
 private void ApplyFormatterOptions(JQGridColumn column)
 {
     if (column.Formatter.Count > 0 && column.Formatter[0] != null)
     {
         JQGridColumnFormatter jQGridColumnFormatter = column.Formatter[0];
         Hashtable             hashtable             = new Hashtable();
         if (jQGridColumnFormatter is LinkFormatter)
         {
             LinkFormatter linkFormatter = (LinkFormatter)jQGridColumnFormatter;
             this._jsonValues["formatter"] = "link";
             if (!string.IsNullOrEmpty(linkFormatter.Target))
             {
                 hashtable["target"] = linkFormatter.Target;
             }
         }
         if (jQGridColumnFormatter is EmailFormatter)
         {
             this._jsonValues["formatter"] = "email";
         }
         if (jQGridColumnFormatter is IntegerFormatter)
         {
             IntegerFormatter integerFormatter = (IntegerFormatter)jQGridColumnFormatter;
             this._jsonValues["formatter"] = "integer";
             if (!string.IsNullOrEmpty(integerFormatter.ThousandsSeparator))
             {
                 hashtable["thousandsSeparator"] = integerFormatter.ThousandsSeparator;
             }
             if (!string.IsNullOrEmpty(integerFormatter.DefaultValue))
             {
                 hashtable["defaultValue"] = integerFormatter.DefaultValue;
             }
         }
         if (jQGridColumnFormatter is NumberFormatter)
         {
             NumberFormatter numberFormatter = (NumberFormatter)jQGridColumnFormatter;
             this._jsonValues["formatter"] = "integer";
             if (!string.IsNullOrEmpty(numberFormatter.ThousandsSeparator))
             {
                 hashtable["thousandsSeparator"] = numberFormatter.ThousandsSeparator;
             }
             if (!string.IsNullOrEmpty(numberFormatter.DefaultValue))
             {
                 hashtable["defaultValue"] = numberFormatter.DefaultValue;
             }
             if (!string.IsNullOrEmpty(numberFormatter.DecimalSeparator))
             {
                 hashtable["decimalSeparator"] = numberFormatter.DecimalSeparator;
             }
             if (numberFormatter.DecimalPlaces != -1)
             {
                 hashtable["decimalPlaces"] = numberFormatter.DecimalPlaces;
             }
         }
         if (jQGridColumnFormatter is CurrencyFormatter)
         {
             CurrencyFormatter currencyFormatter = (CurrencyFormatter)jQGridColumnFormatter;
             this._jsonValues["formatter"] = "currency";
             if (!string.IsNullOrEmpty(currencyFormatter.ThousandsSeparator))
             {
                 hashtable["thousandsSeparator"] = currencyFormatter.ThousandsSeparator;
             }
             if (!string.IsNullOrEmpty(currencyFormatter.DefaultValue))
             {
                 hashtable["defaultValue"] = currencyFormatter.DefaultValue;
             }
             if (!string.IsNullOrEmpty(currencyFormatter.DecimalSeparator))
             {
                 hashtable["decimalSeparator"] = currencyFormatter.DecimalSeparator;
             }
             if (currencyFormatter.DecimalPlaces != -1)
             {
                 hashtable["decimalPlaces"] = currencyFormatter.DecimalPlaces;
             }
             if (!string.IsNullOrEmpty(currencyFormatter.Prefix))
             {
                 hashtable["prefix"] = currencyFormatter.Prefix;
             }
             if (!string.IsNullOrEmpty(currencyFormatter.Prefix))
             {
                 hashtable["suffix"] = currencyFormatter.Suffix;
             }
         }
         if (jQGridColumnFormatter is CheckBoxFormatter)
         {
             CheckBoxFormatter checkBoxFormatter = (CheckBoxFormatter)jQGridColumnFormatter;
             this._jsonValues["formatter"] = "checkbox";
             if (checkBoxFormatter.Enabled)
             {
                 hashtable["disabled"] = false;
             }
         }
         if (jQGridColumnFormatter is CustomFormatter)
         {
             CustomFormatter customFormatter = (CustomFormatter)jQGridColumnFormatter;
             if (!string.IsNullOrEmpty(customFormatter.FormatFunction))
             {
                 this._jsonValues["formatter"] = customFormatter.FormatFunction;
             }
             if (!string.IsNullOrEmpty(customFormatter.UnFormatFunction))
             {
                 this._jsonValues["unformat"] = customFormatter.UnFormatFunction;
             }
         }
         if (hashtable.Count > 0)
         {
             this._jsonValues["formatoptions"] = hashtable;
         }
     }
 }