Let's say I have a grid containing a set of Schools, and each of the schools has a detail table containing a list of courses. I'm looking for a way to filter the schools and courses by course title through the use of a FilterExpression. As of now, I am iterating through each school item and and setting the FilterExpression of the NestedTableView. Not only is this method cumbersome, but it only filters the courses, not the schools, so any schools without courses after filtering display "No child records to display."
4 Answers, 1 is accepted
0

Dylan
Top achievements
Rank 1
answered on 24 Feb 2014, 07:52 PM
To clarify, I do not want the rows (schools) that have empty detail tables (no courses) to be displayed.
0

Princy
Top achievements
Rank 2
answered on 25 Feb 2014, 11:13 AM
Hi Dylan,
I guess you want to set the Initial Filter for Detailtable. You can set the FilterExpression inside the OnDetailTableDataBind event as follows:
C#:
Below code snippet shows how to hide the Detailtable with no records, you may hide its expand/collapse image also.
C#:
Thanks,
Princy
I guess you want to set the Initial Filter for Detailtable. You can set the FilterExpression inside the OnDetailTableDataBind event as follows:
C#:
protected
void
RadGrid1_DetailTableDataBind(
object
source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch
(e.DetailTableView.Name)
{
case
"Courses"
:
{
e.DetailTableView.FilterExpression =
"(CoursesColumn = SomeValue)"
;
GridColumn column1 = e.DetailTableView.GetColumnSafe(
"CoursesColumn"
);
column1.CurrentFilterFunction = GridKnownFunction.Contains;
break
;
}
}
}
Below code snippet shows how to hide the Detailtable with no records, you may hide its expand/collapse image also.
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNoRecordsItem) e.Item.OwnerTableView.Visible =
false
;
//Hide Detailtable with no Records
}
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
HideExpandColumnRecursive(RadGrid1.MasterTableView);
//Hide Expand/Collapse image
}
public
void
HideExpandColumnRecursive(GridTableView tableView)
{
GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
foreach
(GridNestedViewItem nestedViewItem
in
nestedViewItems)
{
foreach
(GridTableView nestedView
in
nestedViewItem.NestedTableViews)
{
if
(nestedView.Items.Count == 0)
{
TableCell cell = nestedView.ParentItem[
"ExpandColumn"
];
cell.Controls[0].Visible =
false
;
cell.Text =
" "
;
// nestedView.ParentItem.Visible = false; //To hide the parent row
}
if
(nestedView.HasDetailTables)
{
HideExpandColumnRecursive(nestedView);
}
}
}
}
Thanks,
Princy
0

Dylan
Top achievements
Rank 1
answered on 25 Feb 2014, 04:06 PM
Thanks for the reply Princy. Unfortunately, this is not exactly what I was looking for. The solution you provided only hides the detail tables, but it doesn't filter their parent items out of the school table. I'm looking for a way to filter the schools by course title. In SQL, it would look like this:
Hopefully this is a little more clear.
Thanks,
-Dylan
select
*
from
Schools
join
Courses
on
Courses.SchoolId = Schools.SchoolId
where
Courses.CourseTitle
like
'%filter_value%'
Hopefully this is a little more clear.
Thanks,
-Dylan
0
Hi Dylan,
I have to say that the desired functionality can not be achieved since the CourseTitle field is not included in the Scools table definition. However you can achieve the desired effect by first filtering the result and then binding it to the grid. For example if the grid uses advanced data-biding(like demonstrated here) you can use the SQL select command from your last post to populate the RadGrid. As a result of this only the schools with the desired course will be available.
Regards,
Angel Petrov
Telerik
I have to say that the desired functionality can not be achieved since the CourseTitle field is not included in the Scools table definition. However you can achieve the desired effect by first filtering the result and then binding it to the grid. For example if the grid uses advanced data-biding(like demonstrated here) you can use the SQL select command from your last post to populate the RadGrid. As a result of this only the schools with the desired course will be available.
Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.