Exemple #1
0
        /// <summary>
        /// grid mods extension
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="grid"></param>
        /// <param name="setCfg"></param>
        /// <returns></returns>
        public static Grid <T> Mod <T>(this Grid <T> grid, Action <GridModCfg> setCfg = null)
        {
            if (setCfg != null)
            {
                var cfg = new GridModCfg();
                setCfg(cfg);
                var info = cfg.GetInfo();
                var mods = new List <string>();
                if (info.PageSize)
                {
                    mods.Add("awem.gridPageSize");
                }
                if (info.PageInfo)
                {
                    mods.Add("awem.gridPageInfo");
                }
                if (info.ColumnsSelector)
                {
                    mods.Add("awem.gridColSel");
                }
                if (info.InfiniteScroll)
                {
                    mods.Add("awem.gridInfScroll");
                }

                if (info.AutoMiniPager)
                {
                    mods.Add("awem.gridAutoMiniPager");
                }
                else if (info.MiniPager)
                {
                    mods.Add("awem.gridMiniPager");
                }

                if (info.InlineEdit)
                {
                    mods.Add("awem.gridInlineEdit('" + info.CreateUrl + "','"
                             + info.EditUrl + "', "
                             + info.OneRow.ToString().ToLower() + ","
                             + info.RelOnSav.ToString().ToLower() + ")");
                }

                if (info.Loading)
                {
                    mods.Add("awem.gridLoading");
                }

                var opt = new { G = info.GridIds };
                if (info.GridIds == null || info.GridIds.Length == 0)
                {
                    opt = null;
                }

                if (info.MovableRows)
                {
                    mods.Add(string.Format("awem.gridMovRows({0})", Autil.Serialize(opt)));
                }

                if (info.CustomMods != null)
                {
                    mods.AddRange(info.CustomMods);
                }

                grid.Mod(mods.ToArray());

                grid.BeforeRenderFuncs.Add(g =>
                {
                    var autohide = false;
                    foreach (var column in g.GetColumns())
                    {
                        var o = column.Tag as ColumnModTag;

                        if (info.ColumnsAutohide)
                        {
                            autohide = true;

                            if (o == null)
                            {
                                o          = new ColumnModTag();
                                column.Tag = o;
                            }

                            if (!o.Autohide.HasValue)
                            {
                                o.Autohide = 1;
                            }

                            if (o.Nohide)
                            {
                                o.Autohide = 0;
                            }
                        }
                        else if (o != null && o.Autohide > 0)
                        {
                            autohide = true;
                        }
                    }

                    if (autohide)
                    {
                        g.GetMods().Add("awem.gridColAutohide");
                    }
                });
            }

            return(grid);
        }
Exemple #2
0
 internal InlineFuncOptions(ColumnModTag tag)
 {
     AddParams = new List <string>();
     this.tag  = tag;
 }