public ActionResult GetItems(GridParams g, bool collapsed) { //passing 2 Functions MakeFooter and MakeHeader to customize header and add footer var builder = new GridModelBuilder <Lunch>(Db.Lunches.AsQueryable(), g) { Key = "Id", Map = o => new { o.Id, o.Person, o.Food, Date = o.Date.ToShortDateString(), 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}, Max Price = {3} )", gr.Header, val, gr.Items.Count(), gr.Items.Max(o => o.Price)), Collapsed = collapsed }); } }; return(Json(builder.Build())); }
/*end1*/ /*begin2*/ public ActionResult LazyTree(GridParams g) { var rootNodes = Db.TreeNodes.Where(o => o.Parent == null); var builder = new GridModelBuilder <TreeNode>(rootNodes.AsQueryable(), g) { Key = "Id", // required for the TreeGrid GetChildren = (node, nodeLevel) => { var children = Db.TreeNodes.Where(o => o.Parent == node).AsQueryable(); // set this node as lazy when it's above level 1 (relative), it has children, and this is not a lazy request already if (nodeLevel > 1 && children.Any() && g.Key == null) { return(Awe.LazyNode); } return(children); }, GetItem = () => // used for lazy loading { var id = Convert.ToInt32(g.Key); return(Db.TreeNodes.FirstOrDefault(o => o.Id == id)); }, Map = o => new { o.Name, o.Id } }; return(Json(builder.Build())); }
/*begin1*/ public ActionResult SimpleTree(GridParams g) { var rootNodes = Db.TreeNodes.Where(o => o.Parent == null); var builder = new GridModelBuilder <TreeNode>(rootNodes.AsQueryable(), g) { Key = "Id", //required for the TreeGrid GetChildren = (node, nodeLevel) => Db.TreeNodes.Where(o => o.Parent == node).AsQueryable(), Map = o => new { o.Name, o.Id } }; return(Json(builder.Build())); }
/*end2*/ /*begin3*/ //clear nodesAdded on aweload public ActionResult CrudTree(GridParams g, string name, int[] nodesAdded) { name = name ?? ""; nodesAdded = nodesAdded ?? new int[] { }; var result = Db.TreeNodes.Where(o => o.Name.ToLower().Contains(name.ToLower()) || nodesAdded.Contains(o.Id)).ToList(); var searchResult = result.ToList(); foreach (var treeNode in searchResult) { AddParentsTo(result, treeNode); } var roots = result.Where(o => o.Parent == null); var model = new GridModelBuilder <TreeNode>(roots.AsQueryable(), g) { Key = "Id", GetChildren = (node, nodeLevel) => { // non lazy version //var children = result.Where(o => o.Parent == node).ToArray(); //return children.AsQueryable(); var children = result.Where(o => o.Parent == node).AsQueryable(); // set this node as lazy when it's above level 1 (relative), it has children, and this is not a lazy request already if (nodeLevel > 1 && children.Any() && g.Key == null) { return(Awe.LazyNode); } return(children); }, GetItem = () => // used for grid api updateItem { var id = Convert.ToInt32(g.Key); return(Db.TreeNodes.FirstOrDefault(o => o.Id == id)); }, Map = MapNode }; return(Json(model.Build())); }
public ActionResult GridGetItems(GridParams g, string search) { search = (search ?? "").ToLower(); //var list = mapdb.Mappers.Where(o => o.ID.ToLower().Contains(search) || o.Product.ToLower().Contains(search)); var list = _mapdb.Mappers.Where(o => o.Id.ToString() == search); var builder = new GridModelBuilder <Mapper>(list.AsQueryable(), g) { Key = "Id", //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 = collapsed // }; //} }; var j = builder.Build(); return(Json(j)); //return Json(new GridModelBuilder<Mapper>(list.OrderByDescending(o => o.ID).AsQueryable(), g) //{ // Key = "Id", // needed for api select, update, tree, nesting, EF // GetItem = () => mapdb.Mappers.Where(o => o.ID == (Convert.ToInt32(g.Key)) //}.Build()); }
public ActionResult GetItems(GridParams g, int[] abc, bool collapsed) { //passing 2 Functions MakeFooter and MakeHeader to customize header and add footer try { var builder = new GridModelBuilder <variable_vw>(db.variable_vw.AsQueryable(), g) { Key = "Id", //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}, Max Price = {3} )", gr.Header, val, 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); } }
public ActionResult CohortGetItems(GridParams g, string IDList) { if (!string.IsNullOrEmpty(IDList)) { Entities db = new Entities(); MicaRepository ado = new MicaRepository(); IDList = IDList.Replace("[", ""); IDList = IDList.Replace("]", ""); IDList = IDList.Replace("\"", ""); //List<string> nodes = IDList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); String[] nodes = IDList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); //passing 2 Functions MakeFooter and MakeHeader to customize header and add footer try { var dt = db.short_variable_vw.ToList().Where(o => nodes.Contains(o.nid.ToString())); //var dt = ado.GetVariable_vw(GroupedIds); //var builder = new GridModelBuilder<variable_vw>(db.variable_vw.AsQueryable(), g) var builder = new GridModelBuilder <short_variable_vw>(dt.AsQueryable(), g) { Key = "nid" }; var j = builder.Build(); return(Json(j)); } catch (Exception ex) { string message = ex.Message; return(null); } } return(null); }
// 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); }