예제 #1
0
        internal static string GetAttachEditorsFunction(JQGrid grid, string editorType, string editorControlID)
        {
            new JavaScriptSerializer();
            GridUtil.GetListOfColumns(grid);
            GridUtil.GetListOfEditors(grid);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("function(el) {");
            stringBuilder.Append("setTimeout(function() {");
            stringBuilder.AppendFormat("var ec = '{0}';", editorControlID);
            if (editorType == "datepicker")
            {
                stringBuilder.Append("if (typeof(jQuery(el).datepicker) !== 'function')");
                stringBuilder.Append("alert('JQDatePicker javascript not present on the page. Please, include jquery.jqDatePicker.min.js');");
                stringBuilder.Append("jQuery(el).datepicker( eval(ec + '_dpid') );");
            }
            if (editorType == "autocomplete")
            {
                stringBuilder.Append("if (typeof(jQuery(el).autocomplete) !== 'function')");
                stringBuilder.Append("alert('JQAutoComplete javascript not present on the page. Please, include jquery.jqAutoComplete.min.js');");
                stringBuilder.Append("jQuery(el).autocomplete( eval(ec + '_acid') );");
            }
            stringBuilder.Append("},200);");
            stringBuilder.Append("}");
            return(stringBuilder.ToString());
        }
예제 #2
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);
        }