[CLOSED] TreeGrid : Check child checkbox with parent checkbox checked

Page 4 of 4 FirstFirst ... 234
  1. #31
    I think this is not possible with current database structure.
    Why not? The following example demonstrates:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    
    namespace TreeGridMVC2._5.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
            public ActionResult Index()
            {
                return View();
            }
    
            private NodeCollection data()
            {
                List<module> mod = module.GenarateModule();
                List<submodule> submod = submodule.GenarateSubModule();
                List<menu> mnu = menu.GenarateMenu();
                NodeCollection n = new NodeCollection();
                Node n_mod = null;
                Node n_submod = null;
                Node n_menu = null;
    
                foreach (module obj_mod in mod)
                {
                    var v_submod = submod.FindAll(item => item.moduleid == obj_mod.moduleid);
    
                    n_mod = new Node();
                    n_mod.Icon = Icon.Folder;
                    n_mod.Expanded = false;
                    n_mod.AttributesObject =
                        new moduleAttributes
                        {
                            moduleid = obj_mod.moduleid,
                            name = obj_mod.modulename,
                            p1 = false,
                            p2 = false,
                            p3 = false,
                            p4 = false
                        };
    
                    foreach (submodule obj_submodule in v_submod)
                    {
                        var v_menu = mnu.FindAll(item => item.submoduleid == obj_submodule.submoduleid);
                        n_submod = new Node();
                        n_submod.Icon = Icon.Folder;
                        n_submod.Expanded = false;
    
                        n_submod.AttributesObject =
                            new submoduleAttributes
                            {
                                submoduleid = obj_submodule.submoduleid,
                                name = obj_submodule.submodulename,
                                p1 = false,
                                p2 = false,
                                p3 = false,
                                p4 = false
                            };
    
                        foreach (menu obj_menu in v_menu)
                        {
                            n_menu = new Node();
                            n_menu.Icon = Icon.Folder;
                            // n_menu.Expanded = true;
                            n_menu.Leaf = true;
                            n_menu.AttributesObject =
                                new menuAttributes
                                {
                                    menuid = obj_menu.menuid,
                                    name = obj_menu.menuname,
                                    p1 = obj_menu.p1,
                                    p2 = obj_menu.p2,
                                    p3 = obj_menu.p3,
                                    p4 = obj_menu.p4
                                };
                            n_submod.Children.Add(n_menu);                        
                        }
                        BubbleToParent(n_submod);   
                        n_mod.Children.Add(n_submod);
                        
                    }
                    BubbleToParent(n_mod);
                    n.Add(n_mod);
                }
    
                return n;
            }
    
            private void BubbleToParent(Node parent)
            {
                bool allP1Checked = true;
                bool allP2Checked = true;
                bool allP3Checked = true;
                bool allP4Checked = true;
    
                foreach (Node child in parent.Children)
                {
                    nodeAttributes attrb = (nodeAttributes)child.AttributesObject;
                    if (attrb.p1 != allP1Checked)
                    {
                        allP1Checked = false;
                    }
                    if (attrb.p2 != allP2Checked)
                    {
                        allP2Checked = false;
                    }
                    if (attrb.p3 != allP3Checked)
                    {
                        allP3Checked = false;
                    }
                    if (attrb.p4 != allP4Checked)
                    {
                        allP4Checked = false;
                    }
                }
    
                nodeAttributes subAttrb = (nodeAttributes)parent.AttributesObject;
                subAttrb.p1 = allP1Checked;
                subAttrb.p2 = allP2Checked;
                subAttrb.p3 = allP3Checked;
                subAttrb.p4 = allP4Checked;
            }
    
            public ActionResult genaratemenuajax(string node)
            {
    
                if (node == "Root")
                {
                    return this.Content(data().ToJson());
                }
    
                return new HttpStatusCodeResult((int)System.Net.HttpStatusCode.BadRequest);
            }
        }
    
        public class nodeAttributes
        {
            public string name { get; set; }
            public bool p1 { get; set; }
            public bool p2 { get; set; }
            public bool p3 { get; set; }
            public bool p4 { get; set; }
        }
    
        public class moduleAttributes : nodeAttributes
        {
            public int moduleid { get; set; }
        }
    
        public class submoduleAttributes : nodeAttributes
        {
            public int submoduleid { get; set; }        
        }
    
        public class menuAttributes : nodeAttributes
        {
            public int menuid { get; set; }
        }
    
        public class module
        {
            public int moduleid { get; set; }
            public string modulename { get; set; }
    
            public static List<module> GenarateModule()
            {
                List<module> l = new List<module>();
                for (int i = 1; i <= 2; i++)
                {
                    var v = new module();
    
    
                    v.moduleid = i;
                    v.modulename = "Module " + i.ToString();
                    l.Add(v);
    
                }
                return l;
            }
        }
    
        public class submodule
        {
            public int moduleid { get; set; }
            public int submoduleid { get; set; }
            public string submodulename { get; set; }
    
            public static List<submodule> GenarateSubModule(int modid = 10)
            {
                List<submodule> l = new List<submodule>();
                for (int j = 1; j <= modid; j++)
                {
                    for (int i = 1; i <= 2; i++)
                    {
                        var v = new submodule();
    
                        v.moduleid = j;
                        v.submoduleid = i;
                        v.submodulename = "SubModule " + i.ToString();
                        l.Add(v);
    
                    }
                }
                return l;
            }
        }
    
        public class menu
        {
            public int menuid { get; set; }
            public int submoduleid { get; set; }
            public string menuname { get; set; }
            public bool p1 { get; set; }
            public bool p2 { get; set; }
            public bool p3 { get; set; }
            public bool p4 { get; set; }
    
    
            public static List<menu> GenarateMenu(int submodid = 10)
            {
                List<menu> l = new List<menu>();
                for (int j = 1; j <= submodid; j++)
                {
                    for (int i = 1; i <= 2; i++)
                    {
                        var v = new menu();
    
                        v.submoduleid = j;
                        v.menuid = i;
                        v.menuname = "Menu " + i.ToString();
                        if (i % 2 == 0) v.p1 = true;        // just to check out everything works
                        v.p2 = false;
                        v.p3 = true;
                        v.p4 = true;
                        l.Add(v);
    
                    }
                }
                return l;
            }
        }
    }
  2. #32
    Hi @Mimisss
    Thanks for your beautiful code .I am not aware of that.but I think http://forums.ext.net/showthread.php...l=1#post234931 in this post we need to add a else also.

    if (allCheckStatus) {
           n.set(obj.dataIndex, node.data[obj.dataIndex]);
      }
     else {
            n.set(obj.dataIndex, false);
      }
    If we not add the else part then I see parent check boxes are checked when all children are checked but not unchecked when a child unchecked .please correct me if I wrong.
    I will post full sample very soon may be tomorrow.
  3. #33
    Both the javascript and the C# code presented in the previous posts work as intended. That is, when a parent is checked or unckecked all children are checked or unchecked, too. When all children are checked or unchecked then a parent is checked or unchecked.

    Please, feel free to modify the code to suit your specific needs. Various checking / unchecking schemes are possible and you do have the basis to implement them.
  4. #34
    Hi,
    I see for check box unchecked .x-grid-checkheader ,and for checked .x-grid-checkheader x-grid-checkheader-checked this 2 css class is responsible ,so if I want so set a background image to the check boxes for checked/unchecked how I change this css dynamically ?please give me some clue.
  5. #35
    This thread has already expanded to answer three different questions. The last question really belongs to a new thread even though I am not sure what's the point of a checkbox with a background image.
  6. #36
    Yes.please close this tread ,I will post a new question .Thank you very much for all your help.
Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. [CLOSED] Another way to check checkbox is checked ot not....
    By rosua in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 21, 2012, 5:39 AM
  2. [CLOSED] Check all checkbox for TreeGrid
    By bakardi in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 04, 2012, 7:25 AM
  3. Replies: 11
    Last Post: Mar 14, 2012, 10:12 AM
  4. Replies: 1
    Last Post: Aug 13, 2009, 9:37 AM
  5. Replies: 0
    Last Post: Jun 25, 2009, 12:16 PM

Posting Permissions