This is a migrated thread and some comments may be shown as answers.

update group checkbox when Data item checkbox are selected

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Dec 2015, 04:39 PM

I have a grid with a that I dynamically created a checkbox on the Group Header. I am trying to toggle the checkboxes in the data item to check or uncheck the group checkbox. The code below is selecting the Header checkbox and not the group checkbox. How can I acheive this?

protected void ToggleRowSelection(object sender, EventArgs e)
        {
            ((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
            bool checkHeader = true;
                foreach (GridDataItem dataItem in rgvFunctions.MasterTableView.Items)
                {
                    if (!(dataItem.FindControl("isFunction") as CheckBox).Checked)
                    {
                        checkHeader = false;
                        break;
                    }
                }
               
       
            GridHeaderItem headerItem = rgvFunctions.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
            (headerItem.FindControl("CheckAll") as CheckBox).Checked = checkHeader;
           
        }

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Dec 2015, 07:37 AM
Hello Andrew,

This requirement is not supported out of the box. You can try to implement some kind of custom jQuery solution using CSS classes or other indication or log it as a feature request in our improvements portal and our dev team may consider implementing it for the future releases:
http://feedback.telerik.com/Project/108


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Andrew
Top achievements
Rank 1
answered on 24 Dec 2015, 12:21 PM

I found the solution. I first find the GroupHeader and iterate through the child 

 

protected void ToggleRowSelection(object sender, EventArgs e)
        {
            ((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
            bool checkHeader = true;
            foreach (GridGroupHeaderItem headerItem in rgvFunctions.MasterTableView.GetItems(GridItemType.GroupHeader))
            {
                checkHeader = true;
                GridItem[] children = headerItem.GetChildItems();
                foreach (GridItem child in children)
                {
                    if (!(child.FindControl("isFunction") as CheckBox).Checked)
                    {
                        checkHeader = false;
                        break;
                    }
                }

                var checkbox = headerItem.FindControl("CheckAll") as CheckBox;
                   checkbox.Checked = checkHeader;
            }
        }

0
Eyup
Telerik team
answered on 25 Dec 2015, 12:30 PM
Hello Andrew,

Thank you for sharing your specific approach with our community. I hope it may prove helpful to other developers as well.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or