Hi all,
I have a Tree Grid with AutoCheckHierarchy enabled.
Which event triggers for each child row which gets automatically checked by parent?
RowSelected or CheckboxChange get triggered only once when parent checkbox gets clicked.
I need to access the row data of every child.
Hi John,
Thanks for contacting syncfusion forum.
Query: Which event triggers for each child row which gets automatically checked by parent?
While selecting the parent record, the checkboxchange event or rowselected event triggers only once. While selecting the child (i.e child gets automatically checked by the parent), it will not trigger any events. If you want to get the child row details, we suggest you follow the second query solution.
Query2: I need to access the row data of every child.
We achieved your query by using the RowSelected event and the GetCheckedRowIndexes and GetCurrentViewRecords methods of the Treegrid. Using the GetCheckedRowindexes method, you can get the checked child and parent row indexes. Using this index, you can get the record in the GetCurrentViewRecords method.
Please refer to the below code snippet,
|
<SfTreeGrid @ref='TreeGrid' IdMapping="TaskId" ParentIdMapping="ParentId" DataSource="@TreeGridData" TreeColumnIndex="1" AutoCheckHierarchy="true"> <TreeGridEvents TValue='TreeData.BusinessObject' CheckboxChange="checkboxchange" RowSelected='selected' ></TreeGridEvents> …. </SfTreeGrid>
public void checkboxchange(CheckBoxChangeEventArgs<TreeData.BusinessObject> args) { var inx = TreeGrid.GetCheckedRowIndexes(); var selectedchecbox = args.SelectedRowIndexes; // collect the checbox index var rec = TreeGrid.GetCurrentViewRecords(); } public void selected(RowSelectEventArgs<TreeData.BusinessObject> args) { var inx = TreeGrid.GetCheckedRowIndexes(); var rec = TreeGrid.GetCurrentViewRecords(); } } |
Kindly get back to us for further assistance.
Regards,
Pon selva
Hi, thank you for your suggestion. I will try that.
I have one more question which is related to the filter functionality of the treegrid.
I am using custom adapter to load data from the database and there is also the logic for the filtration, which is working fine with the results matching my criteria.
The problem is that this way I cannot display all parent and children records when I am using the default Filtration Hierarchy Mode set to Both.
The filter filters the data correctly but if a child got matched but its parent did not, the child won't get displayed at all.
If I remove my Custom Adapter and put back the DataSource as the way to populate the TreeGrid, everything works fine.
This is not working for me though, because I have more than 5 thousand records which I only want to load on demand and the Custom Adaptor is the only way.
It would be great if you have a solution for that matter also, to be able to show both parent and child records after filtration.
Cheers
Hi John,
Thanks for the update.
Query: I cannot display all parent and children records when I am using the default Filtration Hierarchy Mode set to Both with custom adaptor
We checked your query by preparing sample, but we were unable to reproduce the issue at our end. While using the custom adaptor you need to handle the filter data.
Please refer to the below code example,
|
<SfTreeGrid @ref="treeGrid" TValue="TreeData.BusinessObject" AllowPaging="true" AllowFiltering="true" HasChildMapping="isParent" IdMapping="TaskId" ParentIdMapping="ParentId" TreeColumnIndex="1" AllowSorting="true" > <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> <TreeGridPageSettings PageSizeMode="PageSizeMode.Root"></TreeGridPageSettings> <TreeGridFilterSettings HierarchyMode="@FilterHierarchyMode.Both"></TreeGridFilterSettings>
………..
public class CustomAdaptor : DataAdaptor { // Performs data Read operation public override object Read(DataManagerRequest dm, string key = null) { filterCount = null; IEnumerable<TreeData.BusinessObject> DataSource = TreeGridData; if (dm.Search != null && dm.Search.Count > 0) { // Searching DataSource = DataOperations.PerformSearching(DataSource, dm.Search); } if (dm.Sorted != null && dm.Sorted.Count > 0) { // Sorting DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted); }
if (dm.Where != null && dm.Where.Count > 0) { if (dm.Where[0].Field == null) {
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
} else { DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); } }
int count = DataSource.Cast<TreeData.BusinessObject>().Count(); if (dm.Skip != 0) { //Paging DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); } if (dm.Take != 0) { DataSource = DataOperations.PerformTake(DataSource, dm.Take); } if (dm.Where != null && dm.Where.Count > 0) { if (dm.Where[0].Field == null) { FilteredData.Clear();
filterCount = 0; //For FilterHierarchy mode as "Parent"(default mode), we need to return the parent record of the filtered record along with the actual filtered record //calling FilterHierarchyData to collect the parent data of filtered data by passing filtered data and complete data source as params FilteredData = FilterHierarchyData(DataSource); DataSource = FilteredData; // assigning new list to DataSource and returning } } count = filterCount != null ? (int)filterCount : count; return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; }
public List<TreeData.BusinessObject> FilterHierarchyData(IEnumerable<TreeData.BusinessObject> filterData) { foreach(var data in filterData) { if(data.ParentId !=null) { FilteredData = FilterData(data); // calling FilterData method to add parent to new list } FilteredData.Add(data);//adding filtered data to list } return FilteredData; }
public List<TreeData.BusinessObject> FilterData(TreeData.BusinessObject data) { var parent = TreeGridData.Where(p => p.TaskId == data.ParentId).FirstOrDefault(); if(parent.ParentId != null) { FilteredData = FilterData(parent); FilteredData.Add(parent); } else { var alreadyPresent = FilteredData.FindIndex(d => d.TaskId == parent.TaskId); if (alreadyPresent == -1)// if parent is not present already, then add parent to list { FilteredData.Add(parent); filterCount++; //adding parent data to list
} } return FilteredData; }
|
Please refer to the below sample,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeGridCC1257791185
Kindly get back to us for further assistance.
Regards,
Pon selva