Пример #1
0
        public JqGridData GetJqGridTreeJsonData()
        {
            if (DataListForJqGrid == null || !DataListForJqGrid.Any())
            {
                return(new JqGridData {
                    Total = 0, Page = 0, Records = 0, Rows = Enumerable.Empty <IDictionary <string, object> >(), Userdata = StatFieldData
                });
            }
            //remark:此处Id 和 Pid 一定是字符串,否则树折叠有问题
            var enumerator = DataListForJqGrid.GetEnumerator();

            while (enumerator.MoveNext())
            //foreach (var data in DataListForJqGrid)
            {
                var data = enumerator.Current;
                IDictionary <string, object> item = data as IDictionary <string, object>;
                item["Id"] = item["Id"].ToString();
                if (item["Pid"].ToString().IsMissing() || item["Pid"].ToString() == "~" || item["Pid"].ToString() == "#")
                {
                    item["Pid"] = null;
                }
                else
                {
                    dynamic d = DataListForJqGrid.FirstOrDefault(d => (d as IDictionary <string, object>)["Fid"].ToString() == item["Pid"].ToString());
                    if (d == null)
                    {
                        item["Pid"] = null;
                    }
                    else
                    {
                        item["Pid"] = (d as IDictionary <string, object>)["Id"].ToString();
                    }
                }
                item["level"]  = item["TreeLevel"].ToInt();
                item["loaded"] = true;
                item["isLeaf"] = item["IsFinal"].ToString() == "1" ? true : false;
                if (item["level"].ToInt() < 2)
                {
                    item["expanded"] = true;
                }
                //else
                //{
                //    item["expanded"] = false;
                //}
            }
            var jsonObj = new JqGridData
            {
                Total    = this.PageCount,
                Page     = this.CurrentPage,
                Records  = this.TotalCount,
                Rows     = DataListForJqGrid,// DataListForJqGrid.ToArray(),
                Userdata = StatFieldData
            };

            return(jsonObj);
        }
Пример #2
0
        /// <summary>
        /// 查询结果数据集合的JSON字符串(jqGrid的JSON格式)
        /// </summary>
        public JqGridData GetJqGridJsonData()
        {
            if (DataListForJqGrid == null || !DataListForJqGrid.Any())
            {
                return(new JqGridData {
                    Total = 0, Page = 0, Records = 0, Rows = Enumerable.Empty <IDictionary <string, object> >(), Userdata = StatFieldData
                });
            }
            var jsonObj = new JqGridData
            {
                Total    = this.PageCount,
                Page     = this.CurrentPage,
                Records  = this.TotalCount,
                Rows     = DataListForJqGrid,// DataListForJqGrid.ToArray(),
                Userdata = StatFieldData
            };

            return(jsonObj);
        }