示例#1
0
 public JsonColModel(JQGridColumn column, JQGrid grid) : this(grid)
 {
     this.FromColumn(column);
 }
示例#2
0
        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);
        }
示例#3
0
 public JsonEditDialog(JQGrid grid)
 {
     this._jsonValues = new Hashtable();
     this._grid       = grid;
 }
示例#4
0
 public JsonColModel(JQGrid grid)
 {
     this._jsonValues = new Hashtable();
     this._grid       = grid;
 }
示例#5
0
文件: Util.cs 项目: mhasham/Jq.Grid
        public static string GetPrimaryKeyField(JQGrid grid)
        {
            int primaryKeyIndex = Util.GetPrimaryKeyIndex(grid);

            return(grid.Columns[primaryKeyIndex].DataField);
        }
 public JQGridDataResolvedEventArgs(JQGrid gridModel, IQueryable currentData, IQueryable allData)
 {
     this._currentData = currentData;
     this._allData     = allData;
     this._gridModel   = gridModel;
 }
示例#7
0
文件: Util.cs 项目: mhasham/Jq.Grid
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt, IQueryable data = null)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         response.rows[i] = new Hashtable();
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             JQGridColumn jQGridColumn = grid.Columns[j];
             string       value        = "";
             if (!string.IsNullOrEmpty(jQGridColumn.DataField))
             {
                 int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal;
                 value = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode));
             }
             response.rows[i].Add(jQGridColumn.DataField, value);
         }
         try
         {
             response.rows[i].Add("tree_level", dt.Rows[i]["tree_level"] as int?);
         }
         catch
         {
         }
         try
         {
             object obj = dt.Rows[i]["tree_parent"];
             string value2;
             if (obj is DBNull)
             {
                 value2 = "null";
             }
             else
             {
                 value2 = Convert.ToString(dt.Rows[i]["tree_parent"]);
             }
             response.rows[i].Add("tree_parent", value2);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_leaf", dt.Rows[i]["tree_leaf"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_expanded", dt.Rows[i]["tree_expanded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_loaded", dt.Rows[i]["tree_loaded"] as bool?);
         }
         catch
         {
         }
         try
         {
             response.rows[i].Add("tree_icon", dt.Rows[i]["tree_icon"] as string);
         }
         catch
         {
         }
     }
     return(response);
 }
示例#8
0
文件: Util.cs 项目: mhasham/Jq.Grid
        internal static JsonResult ConvertToTreeJson <TEntity>(JsonTreeResponse response, JQGrid grid, IQueryable <TEntity> Data) where TEntity : class
        {
            JsonResult jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.DenyGet;
            jsonResult.Data = Util.PrepareJsonTreeResponse(response, grid, Data);
            return(jsonResult);
        }
示例#9
0
文件: Util.cs 项目: mhasham/Jq.Grid
        internal static JsonResponse PrepareJsonResponse <TEntity>(JsonResponse response, JQGrid grid, IQueryable <TEntity> data) where TEntity : class
        {
            if (response.records == 0 && !grid.AppearanceSettings.ShowFooter)
            {
                return(response);
            }
            PropertyInfo[] properties = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            int            i          = 0;

            foreach (object c in data)
            {
                List <string> array = new List <string>();
                foreach (JQGridColumn t in grid.Columns)
                {
                    bool fieldFound = false;
                    if (!string.IsNullOrEmpty(t.DataField))
                    {
                        foreach (PropertyInfo prop in properties)
                        {
                            if (t.DataField.ToLower().Equals(prop.Name.ToLower()))
                            {
                                fieldFound = true;
                                if (prop.GetValue(c, null) != null)
                                {
                                    object val  = prop.GetValue(c, null);
                                    string text = (string.IsNullOrEmpty(t.DataFormatString) ? val.ToString() : t.FormatDataValue(val, t.HtmlEncode));
                                    array.Add(text);
                                }
                                else
                                {
                                    array.Add("");
                                }
                                break;
                            }
                        }
                        if (!fieldFound)
                        {
                            array.Add("");
                        }
                    }
                }
                string  id      = array[Util.GetPrimaryKeyIndex(grid)];
                JsonRow jsonRow = new JsonRow();
                jsonRow.id       = id;
                jsonRow.cell     = array.ToArray();
                response.rows[i] = jsonRow;
                i++;
            }
            return(response);
        }
示例#10
0
文件: Util.cs 项目: mhasham/Jq.Grid
        internal static JsonTreeResponse PrepareJsonTreeResponse <TEntity>(JsonTreeResponse response, JQGrid grid, IQueryable <TEntity> data = null) where TEntity : class
        {
            PropertyInfo[] properties = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            int            i          = 0;

            foreach (object c in data)
            {
                List <string> ar = new List <string>();
                foreach (JQGridColumn t in grid.Columns)
                {
                    foreach (PropertyInfo prop in properties)
                    {
                        if (t.DataField.ToLower().Equals(prop.Name.ToLower()))
                        {
                            response.rows[i].Add(t.DataField, prop.GetValue(c, null).ToString());
                            break;
                        }
                    }
                    response.rows[i].Add(t.DataField, "");
                }
                bool   tree_levelExist    = false;
                bool   tree_parentExist   = false;
                bool   tree_leafExist     = false;
                bool   tree_expandedExist = false;
                bool   tree_loadedExist   = false;
                bool   tree_iconExist     = false;
                int    tree_level         = 0;
                string tree_parent        = "null";
                bool   tree_leaf          = false;
                bool   tree_expanded      = false;
                bool   tree_loaded        = false;
                string tree_icon          = "";
                foreach (PropertyInfo prop in properties)
                {
                    if (prop.Name.ToLower() == "tree_level")
                    {
                        tree_levelExist = true;
                        try
                        {
                            tree_level = int.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_level", tree_level);
                    }
                    if (prop.Name.ToLower() == "tree_parent")
                    {
                        tree_parentExist = true;
                        try
                        {
                            tree_parent = prop.GetValue(c, null).ToString();
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_parent", tree_parent);
                    }
                    if (prop.Name.ToLower() == "tree_leaf")
                    {
                        tree_leafExist = true;
                        try
                        {
                            tree_leaf = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_leaf", tree_leaf);
                    }
                    if (prop.Name.ToLower() == "tree_expanded")
                    {
                        tree_expandedExist = true;
                        try
                        {
                            tree_expanded = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_expanded", tree_expanded);
                    }
                    if (prop.Name.ToLower() == "tree_loaded")
                    {
                        tree_loadedExist = true;
                        try
                        {
                            tree_loaded = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_loaded", tree_loaded);
                    }
                    if (prop.Name.ToLower() == "tree_icon")
                    {
                        tree_iconExist = true;
                        try
                        {
                            tree_icon = prop.GetValue(c, null).ToString();
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_icon", tree_icon);
                    }
                }
                if (!tree_levelExist)
                {
                    response.rows[i].Add("tree_level", tree_level);
                }
                if (!tree_parentExist)
                {
                    response.rows[i].Add("tree_parent", tree_parent);
                }
                if (!tree_leafExist)
                {
                    response.rows[i].Add("tree_leaf", tree_leaf);
                }
                if (!tree_expandedExist)
                {
                    response.rows[i].Add("tree_expanded", tree_expanded);
                }
                if (!tree_loadedExist)
                {
                    response.rows[i].Add("tree_loaded", tree_loaded);
                }
                if (!tree_iconExist)
                {
                    response.rows[i].Add("tree_icon", tree_icon);
                }
                i++;
            }
            return(response);
        }
示例#11
0
        private static string GetStartupOptions(JQGrid grid, bool subGrid)
        {
            StringBuilder stringBuilder   = new StringBuilder();
            string        initGrid        = subGrid ? "$('#' + subgrid_table_id)" : string.Format("$('#{0}')", grid.ID);
            string        initPager       = subGrid ? "$('#' + pager_id)" : string.Format("$('#{0}')", grid.ID + "_pager");
            string        pagerSelectorID = subGrid ? "'#' + pager_id" : string.Format("'#{0}'", grid.ID + "_pager");
            string        initParent      = subGrid ? "&parentRowID=' + row_id + '" : string.Empty;
            string        initDataUrl     = (grid.DataUrl.IndexOf("?") > 0) ? "&" : "?";
            string        initEditUrl     = (grid.EditUrl.IndexOf("?") > 0) ? "&" : "?";
            string        initJs          = string.Format("{0}{1}jqGridID={2}{3}", grid.DataUrl, initDataUrl, grid.ID, initParent);
            string        initJsEdit      = string.Format("{0}{1}jqGridID={2}&editMode=1{3}", grid.EditUrl, initEditUrl, grid.ID, initParent);

            if (grid.Columns.Count > 0 && grid.Columns[0].Frozen)
            {
                grid.AppearanceSettings.ShrinkToFit = false;
            }
            stringBuilder.AppendFormat("{0}.jqGrid({{", initGrid);
            stringBuilder.AppendFormat("url: '{0}'", initJs);
            stringBuilder.AppendFormatIfFalse(string.IsNullOrWhiteSpace(grid.EditUrl), ",editurl: '{0}'", initJsEdit);
            stringBuilder.Append(",mtype: 'POST'");
            stringBuilder.Append(",datatype: 'json'");
            stringBuilder.AppendFormat(",page: {0}", grid.PagerSettings.CurrentPage);
            stringBuilder.AppendFormat(",colNames: {0}", GetColNames(grid));
            stringBuilder.AppendFormat(",colModel: {0}", GetColModel(grid));
            stringBuilder.AppendFormat(",viewrecords: true", new object[0]);
            stringBuilder.AppendFormat(",scrollrows: false", new object[0]);
            if (grid.Columns.Count > 0)
            {
                stringBuilder.AppendFormat(",prmNames: {{ id: \"{0}\" }}", Util.GetPrimaryKeyField(grid));
            }
            if (grid.AppearanceSettings.ShowFooter)
            {
                stringBuilder.Append(",footerrow: true");
                stringBuilder.Append(",userDataOnFooter: true");
            }
            if (!grid.AppearanceSettings.ShrinkToFit)
            {
                stringBuilder.Append(",shrinkToFit: false");
            }
            stringBuilder.Append(",headertitles: true");
            if (grid.ColumnReordering)
            {
                stringBuilder.Append(",sortable: true");
            }
            if (grid.AppearanceSettings.ScrollBarOffset != 18)
            {
                stringBuilder.AppendFormat(",scrollOffset: {0}", grid.AppearanceSettings.ScrollBarOffset);
            }
            if (grid.AppearanceSettings.RightToLeft)
            {
                stringBuilder.Append(",direction: 'rtl'");
            }
            if (grid.AutoWidth)
            {
                stringBuilder.Append(",autowidth: true");
            }
            if (grid.ForceFit)
            {
                stringBuilder.Append(",forceFit: true");
            }
            if (!grid.ShrinkToFit)
            {
                stringBuilder.Append(",shrinkToFit: false");
            }
            if (grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Bottom || grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom)
            {
                stringBuilder.AppendFormat(",pager: {0}", initPager);
            }
            if (grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.Top || grid.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom)
            {
                stringBuilder.Append(",toppager: true");
            }
            if (grid.RenderingMode == RenderingMode.Optimized)
            {
                if (grid.HierarchySettings.HierarchyMode != HierarchyMode.None)
                {
                    throw new Exception("Optimized rendering is not compatible with hierarchy.");
                }
                stringBuilder.Append(",gridview: true");
            }
            if (grid.HierarchySettings.HierarchyMode == HierarchyMode.Parent || grid.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild)
            {
                stringBuilder.Append(",subGrid: true");
                stringBuilder.AppendFormat(",subGridOptions: {0}", grid.HierarchySettings.ToJSON());
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.SubGridRowExpanded))
            {
                stringBuilder.AppendFormat(",subGridRowExpanded: {0}", grid.ClientSideEvents.SubGridRowExpanded);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.ServerError))
            {
                stringBuilder.AppendFormat(",errorCell: {0}", grid.ClientSideEvents.ServerError);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowSelect))
            {
                stringBuilder.AppendFormat(",onSelectRow: {0}", grid.ClientSideEvents.RowSelect);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.ColumnSort))
            {
                stringBuilder.AppendFormat(",onSortCol: {0}", grid.ClientSideEvents.ColumnSort);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowDoubleClick))
            {
                stringBuilder.AppendFormat(",ondblClickRow: {0}", grid.ClientSideEvents.RowDoubleClick);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.RowRightClick))
            {
                stringBuilder.AppendFormat(",onRightClickRow: {0}", grid.ClientSideEvents.RowRightClick);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.LoadDataError))
            {
                stringBuilder.AppendFormat(",loadError: {0}", grid.ClientSideEvents.LoadDataError);
            }
            else
            {
                stringBuilder.AppendFormat(",loadError: {0}", "jqGrid_aspnet_loadErrorHandler");
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.GridInitialized))
            {
                stringBuilder.AppendFormat(",gridComplete: {0}", grid.ClientSideEvents.GridInitialized);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.BeforeAjaxRequest))
            {
                stringBuilder.AppendFormat(",beforeRequest: {0}", grid.ClientSideEvents.BeforeAjaxRequest);
            }
            if (!string.IsNullOrEmpty(grid.ClientSideEvents.AfterAjaxRequest))
            {
                stringBuilder.AppendFormat(",loadComplete: {0}", grid.ClientSideEvents.AfterAjaxRequest);
            }
            if (grid.TreeGridSettings.Enabled)
            {
                stringBuilder.AppendFormat(",treeGrid: true", new object[0]);
                stringBuilder.AppendFormat(",treedatatype: 'json'", new object[0]);
                stringBuilder.AppendFormat(",treeGridModel: 'adjacency'", new object[0]);
                string arg5 = "{ level_field: 'tree_level', parent_id_field: 'tree_parent', leaf_field: 'tree_leaf', expanded_field: 'tree_expanded', loaded: 'tree_loaded', icon_field: 'tree_icon' }";
                stringBuilder.AppendFormat(",treeReader: {0}", arg5);
                stringBuilder.AppendFormat(",ExpandColumn: '{0}'", GetFirstVisibleDataField(grid));
                Hashtable hashtable = new Hashtable();
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.CollapsedIcon))
                {
                    hashtable.Add("plus", grid.TreeGridSettings.CollapsedIcon);
                }
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.ExpandedIcon))
                {
                    hashtable.Add("minus", grid.TreeGridSettings.ExpandedIcon);
                }
                if (!string.IsNullOrEmpty(grid.TreeGridSettings.LeafIcon))
                {
                    hashtable.Add("leaf", grid.TreeGridSettings.LeafIcon);
                }
                if (hashtable.Count > 0)
                {
                    stringBuilder.AppendFormat(",treeIcons: {0}", JsonConvert.SerializeObject(hashtable));
                }
            }
            if (!grid.AppearanceSettings.HighlightRowsOnHover)
            {
                stringBuilder.Append(",hoverrows: false");
            }
            if (grid.AppearanceSettings.AlternateRowBackground)
            {
                stringBuilder.Append(",altRows: true");
            }
            if (grid.AppearanceSettings.ShowRowNumbers)
            {
                stringBuilder.Append(",rownumbers: true");
            }
            if (grid.AppearanceSettings.RowNumbersColumnWidth != 25)
            {
                stringBuilder.AppendFormat(",rownumWidth: {0}", grid.AppearanceSettings.RowNumbersColumnWidth.ToString());
            }
            if (grid.PagerSettings.ScrollBarPaging)
            {
                stringBuilder.AppendFormat(",scroll: 1", new object[0]);
            }
            stringBuilder.AppendFormat(",rowNum: {0}", grid.PagerSettings.PageSize.ToString());
            stringBuilder.AppendFormat(",rowList: {0}", grid.PagerSettings.PageSizeOptions.ToString());
            if (!string.IsNullOrEmpty(grid.PagerSettings.NoRowsMessage))
            {
                stringBuilder.AppendFormat(",emptyrecords: '{0}'", grid.PagerSettings.NoRowsMessage.ToString());
            }
            stringBuilder.AppendFormat(",editDialogOptions: {0}", GetEditOptions(grid));
            stringBuilder.AppendFormat(",addDialogOptions: {0}", GetAddOptions(grid));
            stringBuilder.AppendFormat(",delDialogOptions: {0}", GetDelOptions(grid));
            stringBuilder.AppendFormat(",searchDialogOptions: {0}", GetSearchOptions(grid));
            string format;

            if (grid.TreeGridSettings.Enabled)
            {
                format = ",jsonReader: {{ id: \"{0}\", repeatitems:false,subgrid:{{repeatitems:false}} }}";
            }
            else
            {
                format = ",jsonReader: {{ id: \"{0}\" }}";
            }
            stringBuilder.AppendFormat(format, grid.Columns[Util.GetPrimaryKeyIndex(grid)].DataField);
            if (!string.IsNullOrEmpty(grid.SortSettings.InitialSortColumn))
            {
                stringBuilder.AppendFormat(",sortname: '{0}'", grid.SortSettings.InitialSortColumn);
            }
            stringBuilder.AppendFormat(",sortorder: '{0}'", grid.SortSettings.InitialSortDirection.ToString().ToLower());
            if (grid.MultiSelect)
            {
                stringBuilder.Append(",multiselect: true");
                if (grid.MultiSelectMode == MultiSelectMode.SelectOnCheckBoxClickOnly)
                {
                    stringBuilder.AppendFormat(",multiboxonly: true", grid.MultiSelect.ToString().ToLower());
                }
                if (grid.MultiSelectKey != MultiSelectKey.None)
                {
                    stringBuilder.AppendFormat(",multikey: '{0}'", GetMultiKeyString(grid.MultiSelectKey));
                }
            }
            if (!string.IsNullOrEmpty(grid.AppearanceSettings.Caption))
            {
                stringBuilder.AppendFormat(",caption: '{0}'", grid.AppearanceSettings.Caption);
            }
            if (!grid.Width.IsEmpty)
            {
                stringBuilder.AppendFormat(",width: '{0}'", grid.Width.ToString().Replace("px", ""));
            }
            if (!grid.Height.IsEmpty)
            {
                stringBuilder.AppendFormat(",height: '{0}'", grid.Height.ToString().Replace("px", ""));
            }
            if (grid.GroupSettings.GroupFields.Count > 0)
            {
                stringBuilder.Append(grid.GroupSettings.ToJSON());
            }
            stringBuilder.AppendFormat(",viewsortcols: [{0},'{1}',{2}]", "false", grid.SortSettings.SortIconsPosition.ToString().ToLower(), (grid.SortSettings.SortAction == SortAction.ClickOnHeader) ? "true" : "false");
            stringBuilder.AppendFormat("}})\r", new object[0]);
            stringBuilder.Append(GetToolBarOptions(grid, subGrid, pagerSelectorID));
            if (!grid.PagerSettings.ScrollBarPaging)
            {
                stringBuilder.AppendFormat(".bindKeys()", new object[0]);
            }
            stringBuilder.Append(";");
            stringBuilder.Append(GetLoadErrorHandler());
            stringBuilder.Append(";");
            if (grid.HeaderGroups.Count > 0)
            {
                List <Hashtable> list = new List <Hashtable>();
                foreach (JQGridHeaderGroup current in grid.HeaderGroups)
                {
                    list.Add(current.ToHashtable());
                }
                stringBuilder.AppendFormat("{0}.setGroupHeaders( {{ useColSpanStyle:true,groupHeaders:{1} }});", initGrid, JsonConvert.SerializeObject(list));
            }
            if (grid.ToolBarSettings.ShowSearchToolBar)
            {
                stringBuilder.AppendFormat("{0}.filterToolbar({1});", initGrid, new JsonSearchToolBar(grid).Process());
            }
            if (grid.Columns.Count > 0 && grid.Columns[0].Frozen)
            {
                stringBuilder.AppendFormat("{0}.setFrozenColumns();", initGrid);
            }
            return(stringBuilder.ToString());
        }
示例#12
0
        private static string GetSearchOptions(JQGrid grid)
        {
            JsonSearchDialog jsonSearchDialog = new JsonSearchDialog(grid);

            return(jsonSearchDialog.Process());
        }
示例#13
0
        private static string GetDelOptions(JQGrid grid)
        {
            JsonDelDialog jsonDelDialog = new JsonDelDialog(grid);

            return(jsonDelDialog.Process());
        }
示例#14
0
        public static string RenderHtml <T>(JQGrid grid, JQGridRenderMode mode) where T : class
        {
            JQGrid gridT = grid as JQGrid;

            return(RenderHtml(gridT, mode));
        }
示例#15
0
        internal static JQGrid <T> Parse <T>() where T : class
        {
            JQGrid <T> result = new JQGrid <T>();

            result.Columns = new List <JQGridColumn>();
            GridAttribute gridAttr = typeof(T).GetCustomAttributes(typeof(GridAttribute), true).FirstOrDefault() as GridAttribute;

            if (gridAttr != null)
            {
                result.ID               = gridAttr.ID;
                result.AutoWidth        = gridAttr.AutoWidth;
                result.ShrinkToFit      = gridAttr.ShrinkToFit;
                result.DataUrl          = gridAttr.DataUrl;
                result.EditUrl          = gridAttr.EditUrl;
                result.ColumnReordering = gridAttr.ColumnReordering;
                result.RenderingMode    = gridAttr.RenderingMode;
                result.MultiSelect      = gridAttr.MultiSelect;
                result.MultiSelectMode  = gridAttr.MultiSelectMode;
                result.MultiSelectKey   = gridAttr.MultiSelectKey;
                result.Width            = (gridAttr.Width == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Width);
                result.Height           = (gridAttr.Height == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Height);
            }

            PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            //Get Key Attribute
            foreach (PropertyInfo prop in properties)
            {
                bool         key   = false;
                bool         IsNew = false;
                JQGridColumn col   = null;

                System.Object[] attributes = prop.GetCustomAttributes(true);
                foreach (object attr in attributes)
                {
                    //if ((attr as Attribute).TypeId.ToString() == "System.Data.Objects.DataClasses.EdmScalarPropertyAttribute")
                    //{
                    //    if ((attr as System.Data.Objects.DataClasses.EdmScalarPropertyAttribute).EntityKeyProperty == true)
                    //        col.PrimaryKey = true;
                    //}
                    //else


                    if ((attr as Attribute).TypeId.ToString() == "System.ComponentModel.DataAnnotations.KeyAttribute")
                    {
                        key = true;
                        if (col != null)
                        {
                            col.PrimaryKey = key;
                        }
                    }

                    if (attr is GridColumnAttribute)
                    {
                        IsNew = true;
                        GridColumnAttribute GridAttr = (attr as GridColumnAttribute);
                        col                             = new JQGridColumn();
                        col.DataField                   = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField;
                        col.Visible                     = GridAttr.Visible;
                        col.HeaderText                  = (string.IsNullOrEmpty(GridAttr.HeaderText)) ? prop.Name : GridAttr.HeaderText;
                        col.DataType                    = prop.DeclaringType;
                        col.PrimaryKey                  = key;
                        col.DataFormatString            = GridAttr.DataFormatString;
                        col.Fixed                       = GridAttr.Fixed;
                        col.Width                       = GridAttr.Width;
                        col.Sortable                    = GridAttr.Sortable;
                        col.Frozen                      = GridAttr.Frozen;
                        col.Resizable                   = GridAttr.Resizable;
                        col.Editable                    = GridAttr.Editable;
                        col.EditType                    = GridAttr.EditType;
                        col.EditTypeCustomCreateElement = GridAttr.EditTypeCustomCreateElement;
                        col.EditTypeCustomGetValue      = GridAttr.EditTypeCustomGetValue;
                        col.EditorControlID             = GridAttr.EditorControlID;
                        col.SearchType                  = GridAttr.SearchType;
                        col.SearchControlID             = GridAttr.SearchControlID;
                        col.DataType                    = GridAttr.DataType;
                        col.SearchCaseSensitive         = GridAttr.SearchCaseSensitive;
                        col.EditDialogColumnPosition    = GridAttr.EditDialogColumnPosition;
                        col.EditDialogRowPosition       = GridAttr.EditDialogRowPosition;
                        col.EditDialogLabel             = GridAttr.EditDialogLabel;
                        col.EditDialogFieldPrefix       = GridAttr.EditDialogFieldPrefix;
                        col.EditDialogFieldSuffix       = GridAttr.EditDialogFieldSuffix;
                        col.EditActionIconsColumn       = GridAttr.EditActionIconsColumn;
                        col.TextAlign                   = GridAttr.TextAlign;
                        col.Searchable                  = GridAttr.Searchable;
                        col.HtmlEncode                  = GridAttr.HtmlEncode;
                        col.HtmlEncodeFormatString      = GridAttr.HtmlEncodeFormatString;
                        col.ConvertEmptyStringToNull    = GridAttr.ConvertEmptyStringToNull;
                        col.NullDisplayText             = GridAttr.NullDisplayText;
                        col.SearchToolBarOperation      = GridAttr.SearchToolBarOperation;
                        col.FooterValue                 = GridAttr.FooterValue;
                        col.CssClass                    = GridAttr.CssClass;
                        col.Width                       = GridAttr.Width;
                        col.GroupTemplate               = GridAttr.GroupTemplate;
                    }
                }
                if (IsNew)
                {
                    result.Columns.Add(col);
                }
            }
            //return cols;
            return(result);
        }