internal static string GetAttachEditorsFunction(JQGrid grid, string editorType, string editorControlID) { 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($(el).datepicker) !== 'function')"); stringBuilder.Append("alert('JQDatePicker javascript not present on the page. Please, include jquery.jqDatePicker.min.js');"); stringBuilder.Append("$(el).datepicker( eval(ec + '_dpid') );"); } if (editorType == "autocomplete") { stringBuilder.Append("if (typeof($(el).autocomplete) !== 'function')"); stringBuilder.Append("alert('JQAutoComplete javascript not present on the page. Please, include jquery.jqAutoComplete.min.js');"); stringBuilder.Append("$(el).autocomplete( eval(ec + '_acid') );"); } stringBuilder.Append("},200);"); stringBuilder.Append("}"); return stringBuilder.ToString(); }
public static string RemoveQuotesForJavaScriptMethods(string input, JQGrid grid) { string text = input; foreach (JQGridColumn current in grid.Columns) { if (current.Formatter != null) { JQGridColumnFormatter formatter = current.Formatter; if (formatter is CustomFormatter) { CustomFormatter customFormatter = (CustomFormatter)formatter; 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 current2 in current.EditClientSideValidators) { if (current2 is CustomValidator) { CustomValidator customValidator = (CustomValidator)current2; string oldValue2 = string.Format("\"custom_func\":\"{0}\"", customValidator.ValidationFunction); string newValue2 = string.Format("\"custom_func\":{0}", customValidator.ValidationFunction); text = text.Replace(oldValue2, newValue2); } } if (current.EditType == EditType.Custom) { string oldValue3 = string.Format("\"custom_element\":\"{0}\"", current.EditTypeCustomCreateElement); string newValue3 = string.Format("\"custom_element\":{0}", current.EditTypeCustomCreateElement); text = text.Replace(oldValue3, newValue3); oldValue3 = string.Format("\"custom_value\":\"{0}\"", current.EditTypeCustomGetValue); newValue3 = string.Format("\"custom_value\":{0}", current.EditTypeCustomGetValue); text = text.Replace(oldValue3, newValue3); } if ((current.Editable && current.EditType == EditType.DatePicker) || current.EditType == EditType.AutoComplete) { string attachEditorsFunction = GridUtil.GetAttachEditorsFunction(grid, current.EditType.ToString().ToLower(), current.EditorControlID); text = text.Replace(string.Concat(new object[] { '"', "attachEditControlsScript", current.DataField, '"' }), attachEditorsFunction); text = text.Replace('"' + "dataInit" + '"', "dataInit"); } if ((current.Searchable && current.SearchType == SearchType.DatePicker) || current.SearchType == SearchType.AutoComplete) { string attachEditorsFunction2 = GridUtil.GetAttachEditorsFunction(grid, current.SearchType.ToString().ToLower(), current.SearchControlID); text = text.Replace(string.Concat(new object[] { '"', "attachSearchControlsScript", current.DataField, '"' }), attachEditorsFunction2); text = text.Replace('"' + "dataInit" + '"', "dataInit"); } } return(text); }