Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Filtering questions and response lists > Filtering loops > Jagged grids
Jagged grids
Jagged grids are grids in which certain cells are unavailable. The illustration shows a typical example where the Sunday cells are unavailable for weekday newspapers, and the weekday cells are unavailable for Sunday publications.
Jagged grid of newspapers by day of week
This graphic is described in the surrounding text.
You cannot create this type of grid using filtering because every row and column in the grid needs to be displayed. Instead, you can hide the unwanted cells using:
Name.Style.Hidden = True
in the routing section, where:
Name is the question name
The basic structure of the illustrated grid (without the style parameters that define column widths and cell background colors) is as follows. You can find the more complete example in the Scripts\Interview\Frequently Asked Questions\Loops and Grids folder in the DDL installation folder.
DailyNewspapersList define
Telegraph, Independent "The Independent",
Times "The Times", Express "The Express", Mail,
Sun "The Sun", DailyMirror "Daily Mirror"
WeekdayNewspapersList define
Guardian "The Guardian", Star "The Star",
FinancialTimes "The Financial Times"
SundayNewspapersList define
Observer "The Observer",
NewsoftheWorld "The News of the World"
DayList define
Sunday, Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday

JaggedGrid "Please select the newspapers that you read on each day." loop
use SundayNewspapersList sublist,
use WeekdayNewspapersList sublist,
use DailyNewspapersList sublist
} fields
DayQ "" categorical [0..]
{DayList use \\.DayList sublist};
) expand grid;
Hiding cells is all done in the routing section, as shown in the following example:
Dim sunday, weekday, newspaper
' Create some category lists to be used for comparison
sunday = JaggedGrid.DefinedListElements({SundayNewspapersList})
weekday = JaggedGrid.DefinedListElements({WeekdayNewspapersList})

' Hide newspapers as appropriate
For Each newspaper in JaggedGrid.DefinedCategories()
With JaggedGrid[CCategorical(newspaper)].DayQ.Categories.DayList
' If the newspaper is a Sunday newspaper, hide the Monday through
' Saturday categories
If sunday >= newspaper Then
.Monday.Style.Hidden = True
.Tuesday.Style.Hidden = True
.Wednesday.Style.Hidden = True
.Thursday.Style.Hidden = True
.Friday.Style.Hidden = True
.Saturday.Style.Hidden = True
End If

' If the newspaper is a weekday newspaper, hide the Sunday category
If weekday >= newspaper Then
.Sunday.Style.Hidden = True
End If
End With
The code that hides unavailable responses steps through each newspaper in the control list for the JaggedGrid loop. The With...End With statement is simply a more efficient way of writing:
If sunday >= newspaper Then
End If
and hides the cell if the current newspaper is a Sunday one.
The CCategorical function generates references such as:
The way it works is this. In the For Each statement, DefinedCategories() returns a categorical value containing the newspaper in the grid — that is, {Telegraph, The Independent, The Times, ...}. The interviewing program sees this as a list of category values such as {49, 50, 51, ...}, so the loop executes for each category value, so newspapers is set to 49, 50, 51, and so on. Without CCategorical, the With statement would be trying to execute statements such as:
which attempt to index the 49th iteration of the loop. Using CCategorical converts the number 49 into a categorical {49} which the interviewing program understands as Telegraph.
See also
Filtering loops