private GridModel <variable_vw> BuildGridModel(GridParams g) { // retreive Session info created when selections were made to mpre-map grid Dictionary <string, string> GroupedIds = Session["PreMap_GroupedIds"] as Dictionary <string, string>; var dt = ado.GetVariable_vw(GroupedIds); return(new GridModelBuilder <variable_vw>(dt.AsQueryable(), g) { // same as pre-map setup Key = "nid", //Map = o => new { o.Id, o.Person, o.Food, o.Date, o.Price, o.Location, ChefName = o.Chef.FirstName + " " + o.Chef.LastName }, MakeFooter = MakeFooter, MakeHeader = gr => { //get first item in the group var first = gr.Items.First(); //get the grouped column value(s) for the first item var val = string.Join(" ", AweUtil.GetColumnValue(gr.Column, first).Select(ToStr)); return new GroupHeader { Content = string.Format(" {0} : {1} ( Count = {2}, <input type='checkbox' name='id' value='{3}'/> )", gr.Header, val, gr.Items.Count(), //gr.Items.Max(o => o.delta) null), Collapsed = false }; } }.Build()); }
// End JSTree /// <summary> /// get the items for the main PreMapping grid /// <param name="g"></param> /// <param name="abc"></param> /// <param name="collapsed"></param> /// <param name="IDList"></param> /// <returns></returns> public ActionResult GetItems(GridParams g, int[] abc, bool collapsed, string IDList, string search) { search = (search ?? "").ToLower(); if (!string.IsNullOrEmpty(IDList)) { Entities db = new Entities(); DATA.MicaRepository ado = new DATA.MicaRepository(); IDList = IDList.Replace("[", ""); IDList = IDList.Replace("]", ""); IDList = IDList.Replace("\"", ""); //List<string> nodes = IDList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); String[] nodearray = IDList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); // the last item was most recently selected-- find its children and add to the list // ******** Dictionary <string, string> GroupedIds = new Dictionary <string, string>(); string lastgroup = null; foreach (string item in nodearray) { if (item.Contains('_')) // skip top level item, it does not have a node id { string[] i = item.Split('_'); if (i[0] != lastgroup) { // ned to build something like this: (a.tids REGEXP '^243|_243' or a.tids REGEXP '^244|_244') try { GroupedIds.Add(i[0], "a.tids REGEXP " + "'^" + i[1] + "|_" + i[1] + "'"); } catch (ArgumentException) { string cur; // remove the current item that is already in the dictionary; group items into a single string and Add back GroupedIds.TryGetValue(i[0], out cur); GroupedIds.Remove(i[0]); GroupedIds.Add(i[0], cur + " or a.tids REGEXP " + "'^" + i[1] + "|_" + i[1] + "'"); } } } } //passing 2 Functions MakeFooter and MakeHeader to customize header and add footer try { // add this selection to Session Session["PreMap_GroupedIds"] = GroupedIds; Session["PreMap_search"] = search; //var dt = db.variable_vw.ToList().Where(o => nodes.Contains(o.nid.ToString())); var dt = ado.GetVariable_vw(GroupedIds).Where(o => o.study_name.ToLower().Contains(search)); int cnt = dt.Count(); ViewBag.CNT = cnt; //var builder = new GridModelBuilder<variable_vw>(db.variable_vw.AsQueryable(), g) var builder = new GridModelBuilder <variable_vw>(dt.AsQueryable(), g) { Key = "nid", //Map = o => new { o.Id, o.Person, o.Food, o.Date, o.Price, o.Location, ChefName = o.Chef.FirstName + " " + o.Chef.LastName }, MakeFooter = MakeFooter, MakeHeader = gr => { //get first item in the group var first = gr.Items.First(); //get the grouped column value(s) for the first item var val = string.Join(" ", AweUtil.GetColumnValue(gr.Column, first).Select(ToStr)); string content_str = null; if (gr.Column == "field_label_value") { content_str = " <font color='darkslateblue'><b>{0} ({2})</b> : {1} <br/> <b>Item Description</b>: {3} </font> )"; } else { content_str = " <font color='darkslateblue'><b>{0} ({2})</b> : {1} </font>"; } return(new GroupHeader { //Content = string.Format(" <font color='darkslateblue'><b>{0}</b> : {1} <b>Count</b> = {2} <br/> <b>Item Description</b> = {3} </font> )", Content = string.Format(content_str, gr.Header, val, gr.Items.Count(), gr.Items.Max(o => o.body_value) //gr.Items.Count(), //gr.Items.Max(o => o.delta) //null ), Collapsed = collapsed }); } }; var j = builder.Build(); return(Json(j)); } catch (Exception ex) { string message = ex.Message; return(null); } } return(null); }